Skip to content

Sprokets/craft-asset-rev

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 

Repository files navigation

Forked Version

This version has been forked from craft-asset-rev for use with Sprokets Craft sites. If you are not working on a Sprokets Craft site, please go check out the original plugin!

CraftCMS Asset Rev (Cache Busting)

A Twig extension for CraftCMS that allows you to swap out asset file names with their revved version, as defined in a JSON manifest file.

Manifest files would most likely be generated by Grunt/Gulp modules, such as grunt-filerev-assets or gulp-rev.

Why?

In order to speed up the load time of your pages, you can set a far-future expires header on your images, stylesheets and javascript. However, when you update those assets you'll need to update their file names to force the browser to download the updated version.

You could append a query string to the asset url (e.g. css/main.css?v=24), but you should read here to find out why that's not an ideal solution.

Installation

Copy the assetrev folder to your craft/plugins directory and activate it from the Craft plugin settings page. Once activated, you will need to specify the path to your asset manifest file within the plugin settings.

Once activated you can use the rev() function in your templates.

Note: If the plugin can't find your manifest file, it will just return the file name passed into rev(). This is helpful during development as you aren't required to keep rebuilding the manifest file each time you update an asset.

Example

<link rel="stylesheet" href="{{ siteUrl }}{{ rev('css/main.css') }}">

or

<link rel="stylesheet" href="{{ url(rev('css/main.css')) }}">

css/main.css will be replaced with the corresponding hashed filename as defined within your assets manifest .json file.

If you'd like to pull the revised filename from a manifest file that is different to the one you specified within the plugin settings you can pass that through as a second argument.

<link rel="stylesheet" href="{{ siteUrl }}{{ rev('css/main.css', '../assets/') }}">

Manifest file example

{
    "css/main.css": "css/main.a9961d38.css",
    "js/main.js": "js/main.786087f7.js"
}

Roadmap

  • Allow the configuration of the assets.json file path within the admin area

About

CraftCMS plugin to aid cache-busting

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 90.2%
  • HTML 9.8%