A new website for Spatie: backend highlights
For the first time in 4 years we completely redesigned our company website. We launched it today. The site is a simple Laravel app with some technical niceties. True to form we also open sourced the app, you can find the code in this repo on GitHub.
In this blogpost I'd like you to give you a tour behind the scenes.
The past years we've been more and more involved in the open source community. We've created 100+ packages that have been downloaded for over 15 million times. On our website we dedicated an entire section to highlight our efforts. We list all our open source packages and projects.
We use the GitHub API to import most info on our public repositories to the database. The import is done by this console command which is scheduled to run daily.
GitHub doesn't have any info on download counts. That's why there is a seperate command that queries the Packagist API for the download numbers.
Getting involved in open source has a lot of benefits. We think it's important the lower the barrier of entry for those wanting to start contributing to open source. That's why we also list a few easy issues on our repos. These are perfect
Those easy issues, which are recognized by a specific label on an issue, are also imported via the GitHub API. Here's the command that handles the import of easy issues. Notice that any new issue also are automatically tweeted.
Our open source stuff wouldn't be as good if we don't get any help from the community. We are grateful for anyone we improved our code with a PR, fixed a typo for us, opened up an issue to ask us a question or report a problem. Symfony recently started with thanking random contributors on their site. We think this is a nice gesture so we've done that as well. Here's the command that imports a random contributor.
Displaying responsive images
All of our open source stuff falls under a specific license called postcardware. This means that if our code makes it into your production environment you're required to send us a postcard from your hometown. For us is kinda cool to get postcards from over the entire planet. We share every postcard we received on this dedicated page on our site.
We now have about 200 postcards displayed on that page. When I take a picture of a postcard with my phone the filesize is about 4 to 6 MB. If we were to use those images directly that the page size would be about 1GB.
You might think, just create a thumbnail version, but we went on step further. We used our own medialibrary to generate responsive images for those postcards. This means that if you visit the site via a small mobile device your browser will download smaller images than if you were working on a device with a larger monitor. We leverage the
srcset attribute to accomplish this behaviour.
The first time you visit the postcards page you might have noticed that blurry versions of the postcards were displayed. This is a technique called progressive image loading. We inline a blurred svg version of the postcards in the page so that the browser can display that immediately. The browser will replace this with a real image when it gets downloaded.
Here's the markup that is generated by the medialibrary for a responsive image.
Some more background info on how this all works can be found on the relevant page in medialibrary docs.
We think cookie warnings are ugly and make the user experience worse. To avoid having to put such a warning on our site, we decided that our website shouldn't set any cookies at all. If you want to know how you can avoid setting any cookies in a laravel app, read this blogpost by Dieter Stinglhamber.
Our site does have a very small admin section to upload postcards. Because In order for the csrf protection to work on that form we need to set a session cookie. That's why we sneakily change the session driver when visiting that page.
Gathering visitor statistics
Fun fact: "matomo" is a Japanese words that can be translated as "honesty" or "deceny".
Improving performance by caching the response
Without any caching the app is already pretty snappy. On my MacBook Pro (from 2015) response times vary from 150 to 200ms. In my mind that's very acceptable but we can do better.
One of our popular package is laravel-responsecache. It can greatly speed up any laravel application by caching the entire response. If you need some more on how it works, read this blogpost. With that package installed response times average around 50ms.
We took a pramatic approach to invalidate the cache. Whenever something changes in the database we clear the responsecache. That happens in the base Eloquent model.
Our new site was principally designed by Willem Van Bockstal. During development everybody in our company contributed, making this a team effort. We're pretty happy with the results, but we won't stop here. In the coming months we'll add some more content and do some tweaks here and there.
Be sure to check out the guest post by my colleague Willem to know more about what's going on at the front end of our new site.
What do you think of our new site? Let us know in the comments below!
What are your thoughts on "A new website for Spatie: backend highlights"?