Laravel Elixir Tidbit

The case

You do know that multiple <link> and <script> tags will cause your browser to do multiple requests to the server, don’t you?

Well, I am not saying anyone on my team doesn’t, but surely no one cares (at the moment).

In my current project, we have like 20+ <script> tags and the same goes for <link> tags for stylesheets. Most of them are from plugins. I don’t know how long it takes to load those resources one by one (I think Chrome Dev Tools can analyse the timings) but it is horrendous to see all those requests in your browser debugging tool.

So let’s learn another tool so we can optimize both our workflow and our application. Please welcome

Laravel Elixir

The buildup

If you are a Javascript developer, you’ve probably heard or used a task runner such as Gulp or Grunt. Laravel Elixir is a layer of abstraction on top of the task runner in our Laravel app. It uses Gulp internally for the task and it is simpler than to use Gulp directly. You have less stuff to configure.

Here I won’t repeat what Laravel docs say on using Laravel Elixir. You can read it by yourself; it’s pretty straightforward.

I will point out things I found by experimenting with Laravel Elixir instead.

Oh, for you who are running Laravel 5.4, it is renamed to Laravel Mix instead.

TIL

Share this on → Twitter Facebook Google+