Caching and cache busting of images vs. SEO

Let’s say I have the file logo.png in the static/ folder.

Somewhere in my template I want to include the image like this:

<img src="logo.png?v={{ LAST MODIFIED DATE }}" alt="Logo">

Background information

I use the http header Cache-Control public, max-age=31536000, immutable on all my static files but I want to force browser to download the image if there is a new version (and I don’t want to use a hash in file names for SEO reasons).

After some investigation I found the following snippet on this GitHub discussion:

<link rel="stylesheet" href="/css/custom.css?{{ readFile "relative/path/to/css/custom.css" | md5 }}" type="text/css">

with should do the job for my case.

1 Like

If you can. Try using the resource pipeline which does cache busting for you

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.