TRAFEX TRAFEX Consultancy Consultancy
Quickly add a cachebuster to @import statements

Quickly add a cachebuster to @import statements

August 16, 2014

This CLI one-liner searches for .css files with @import statements and adds a ‘cache busting’ query string to it. You can use it to make sure the browser picks up the new CSS files when they are included with @import statements.

Snippet

find . -iname *.css -exec sed -i -e 's/@import "(.*).css"/@import "\1.css?cb=12345"/g' {} ;

Before

@import url('//fonts.googleapis.com/css?family=Francois+One');
@import url('/css/layout.css');
@import url('/css/color.css');

After

@import url('//fonts.googleapis.com/css?family=Francois+One');
@import url('/css/layout.css?cb=12345');
@import url('/css/color.css?cb=12345');
Go back

Recent articles

Articles

10 years of Home Assistant: my favorite software

Ten years of Home Assistant, why it's my favorite software and what my setup looks like.

Read More

Articles

Implementing AI in your application

Lessons learned from implementing an AI feature in Metric Moose

Read More

Articles

Giving structure to your Kubernetes configuration

Best practices for giving structure to your Kubernetes configuration

Read More