Have you seen our video tutorials? Check 'em out!

Versioning css and scripts

keevitaja - 2 weeks ago


Is there an official way versioning stylesheets and scripts? Like with asset_style() add version key or something

huglester - 2 weeks ago

For now I did the old Elixir way. I just compile css/js and output them to public. and in the metadata I echo them like elixir('js/app.js');

I think you know how it works!

ryanthompson - 2 weeks ago

Nothing built in right now no but that's not a bad idea. How would this work do you think?

keevitaja - 2 weeks ago

This versioning is for browser cache busting.

I do not know, how exactly the asset building is working in PyroCMS, but each time the new asset is built/compiled, either it did not exist, asset cache was purged or assets were updated (this is what causes problems), a new version key is generated and injected into the html tag by asset_style or asset_script

<script src="http://site/app.js?v=3434534">

This version key could be some cheap hash like crc32 or similar. No need to have an incremental integer.

ryanthompson - 2 weeks ago

I like that. So randomize it during dev and for production it would remain the same unless maybe a bump command or something?

keevitaja - 2 weeks ago

mhhh, this might actually be better what i was proposing. Like for dev new key is generated for each load but for production you must issue artisan command to pump the version.

thinkgraphical - 1 day ago

+1 for this. Maybe you can get some inspiration from this package: https://github.com/spekkionu/laravel-assetcachebuster

keevitaja - 1 day ago

@ryanthompson any news about this?