Code splitting with Laravel Mix

| 5 min read

Code splitting is bundler feature—if you’re using Laravel Mix, you’re bundling your assets with Webpack—that allows you to split application scripts in multiple files. These can then conditionally be loaded at a later stage.

Read more


Server side rendering JavaScript from PHP

| 10 min read

Server side rendering is a hot topic when it comes to client side applications. Unfortunately, it’s not an easy thing to do, especially if you’re not building things in a Node.js environment.

I published two libraries to enable server side rendering JavaScript from PHP: spatie/server-side-rendering and spatie/laravel-server-side-rendering for Laravel apps.

Let’s review some server side rendering concepts, benefits and tradeoffs, and build a server renderer in PHP from first principles.

Read more


A pair of helping hands when naming things

| 1 min read

One of the hardest (and sometimes frustrating) tasks in a programmer’s day-to-day workload is naming things. When I have a hard time finding that perfect word, I generally wind up in one of two situations:

  • I have a plausible name in mind, but I’m not entirely satisfied with it
  • I have no idea what I could possibly name it

Luckily, there are tools out there that can be of help.

Read more


Blade component aliases in Laravel 5.6

| 2 min read

Laravel 5.6 adds the ability to register alias directives for Blade components. Let’s review some background information and examples.

Read more


Passing data to layouts in Blade through extends

| 1 min read

Laravel quick tip! The @extends Blade directive accepts a second (undocumented) parameter to pass data to the parent layout.

Read more


Debugging the dreaded "Class log does not exist" error in Laravel

| 1 min read

Every now and then I come accross a Class log does not exist exception in Laravel. This particular exception is thrown when something goes wrong really early in the application, before the exception handler is instantiated.

Whenever I come across this issue I’m stumped. Mostly it’s related to an invalid configuration issue or an early service provider that throws an exception. I always forget how to debug this, so it’s time to document my solution for tracking down the underlying error.

Read more


Nordic.js 2017 recap

| 2 min read

Last month I travelled up north to my first JavaScript conference: Nordic.js. The entire conference was a great experience: the speakers, the location, the food (kanelbullar!), … Here’s a quick recap of my favorite talks.

Read more


Theme-based views in Laravel using vendor namespaces

| 2 min read

I’m building a multi-tenant Laravel application. One of the requirements of the project is that every client can have their own theme based on their corporate guidelines. By default a few css adjustments will suffice, but some clients request a completely different template.

Conditionally loading a different stylesheet per client is pretty trivial, but in order to use a completely different view per theme you quickly end up typing the same thing over and over across various parts of your application.

Read more


What's in our .babelrc?

| 4 min read

A lot has been going in in JavaScript the past few years. One of my favorite things has been the usage of babel, which allows us to write future JavaScript syntax today. The babel ecosystem has tons of plugins and configuration options, I’d like to elaborate on our usage at Spatie.

Read more


Generate pdfs with Google Chrome on a Forge provisioned server

| 1 min read

This week I needed to export some charts generated with HTML & JavaScript as a pdf file. I already had implemented the charts on a webpage so I wanted a solution that allowed me to use my existing code for the pdfs.

Headless Chrome to the rescue! Chrome can run as a cli tool, and print a pdf file from a url. All I had to do was make some layout tweaks to make everything printer-friendly.

Read more