Cms: Twig filter for cache busting of css and js files

Created on 24 Jul 2018  路  3Comments  路  Source: craftcms/cms

This twig filter would take in path to specific file, and output it with GET parameter, consisting of file modification time (timestamp).

Each time file would change, GET parameter would also change. Ideal for browser cache busting.

For example this:
<script src="{{'scripts/script.js'|updateFile}}"></script>
Outputs:
<script src="scripts/script.js?v=1234556789990"></script>

enhancement site development

Most helpful comment

Andr茅 Elvan's Stamp plugin works marvelously for accomplish exactly this.

All 3 comments

The filter would also need to know the file鈥檚 server path in order to know its modify time.

Andr茅 Elvan's Stamp plugin works marvelously for accomplish exactly this.

I second this FR, but instead of using the modified time, maybe using a hash?

Was this page helpful?
0 / 5 - 0 ratings