Code

BUSTER - Ensure users always get the latest changes to CSS/JS/img's & more using hash based filename

BUSTER - Ensure users always get the latest changes to CSS/JS/img's & more using hash based filename

A Simple PHP script to generate a unique hashed filename based on the actual contents of the file.

Here’s the video Tutorial and overview

Why?

Using a hash-based name system we can be certain when we need to break cache for a user.

Instead of just forcing a cache break every x hours or days.

This ensures if the content ever changes the user definitely gets the latest version!

With this method, we can set basically unlimited cache lengths and rest assured the user gets the latest changes.

Examples:

Hard Example (creating a new file) with a custom third parameter so it goes into a sub-folder of input:
Input:
<link rel="stylesheet" href="<?php cssHashFileName('css/example-stylesheet.css', 'hard', 'cache'); ?>">

Output as seen by users/browser:

<link rel="stylesheet" href="css/cache/example-stylesheet-8n288lb76mk.css">

Soft Example (appending cache busting get string)
Input:
<link rel="stylesheet" href="<?php cssHashFileName('css/example-stylesheet.css', 'soft'); ?>">

Output as seen by users/browser:

<link rel="stylesheet" href="css/example-stylesheet.css?v=8n288lb76mk">

by
by
by
by
by
by