Assets pipeline and page-specific assets


Like most of grav user, I use the asset manager for my project, and I wonder what would be the best way to handle page-specific asset.
Let’s say I will only use the google maps js asset for my page ‘Contact’, would you say it is better to load it just once, but pipelined with all other assets (I assume my assets will be cached and only loaded once) on first load, or do you think I should rather use only used assets on each page?

Thanks for your feedback

There are options to explicitly not pipeline an asset. In my opinion it should come down to size: When minified, does the additional weight of the added asset have a significant impact on the overall pageload? If not, pipeline it so you have one fewer HTTP request on said page(s). If it does, the load should not be imposed upon all other pages.

Though I do not quite know how large the Google Maps JS is, I doubt it is so large that loading it pipelined takes longer than the extra HTTP request.

it’s handled automatically by Grav. Whatever is in the Assets for a given page, is pipelined and saved into assets. The next time you request that same group of assets (be it this one page or another page that has the same assets), it will use the same file. If it’s got different assets, a new file is created for that set of assets.

You can also configure certain CSS or JS to not be pipelined. it’s just an option you pass when you add the asset:

{% do assets.addJs('theme://js/example.js', {'priority':102, 'pipeline':false, 'loading':'async', 'group':'bottom'}) %}

^^^ see the pipeline: false

BTW with the advent of HTTP/2, compressing and pipelining of of assets is sort of moot, as HTTP/2 uses a single persistent connection anyway.

What is the status of HTTP/2 per now? I don’t think I’ve seen much implementation of it yet. From what I read server support is still in development, but the speed seems a lot better compared to HTTP or better-than-or-tied-to SPDY. Still, for now minification and pipelining is a best practice. is running it :slight_smile: We use to control our site, and it has support for it built in. Just turn it on :slight_smile: