WP tip – Forcing a CSS stylesheet refresh

WP tip – Forcing a CSS stylesheet refresh

The scenario

A project is close to completion, then there’s this one thing the client wants changed. You can totally do it. Easy peasy.

Now, if you build a site with code, and not mouse clicking, then you would have edited the stylesheet.

So you change a couple of values and/or properties on the stylesheet.

Cool. Plus, you clear the cache.

All good?

No.

The situation

The people who checked the previous version of the site have the cache on its local storage, and you can’t make everyone use the incognito browser to check the un-cached version of the website to confirm that it’s been changed.

So they only see the version before the stylesheet change.

Hit refresh, nope. Nothing changes. Nope.

 

 

Uuuuuuuuuuuugggghghhhghghghghghghhghgh

So now you got a bunch of people asking “Did you REALLY make those changes? I can’t see them, I refreshed the browser” and so on… until it’s been taken care of.

Make it stop.

The solution

(Disclaimer: You usually won’t be having this problem if you use the additional CSS tab in the customizer, but if you style a whole website, it’s better to actually code the whole thing properly, and not add a couple of quick snippets to the theme, so this solution doesn’t apply to short CSS snippets in the additional CSS field. It’s for large CSS files in the WP enqueue.)

Alright, this is actually way simpler than it seems.

And that’s good, because I had so much frustration with this.

Here’s how to get it done.

Step 1. Connect to your server, go to your child theme folder, and to the folder with the stylesheet.

Step 2. Duplicate the CSS file, and name it something different. Like with a 2 at the end.

Step 3. Now go to functions.php and change the name of the enqueued CSS file to the new one.

And… you’re done.

 

That’s it. The browser will have to load the new stylesheet because it realizes it’s a different file.

PS. I’ve read that this works with adding CSS file versions too, but I couldn’t get it to work with my setups reliably, so I just go with a full filename change.

 

 

Photo by Justyn Warner on Unsplash

Get Breakdance

Breakdance is, in my opinion, the best page/site builder on the market, which is why all my tutorials use Breakdance. It's also why I have an affiliate link. You don't pay extra, but I get a little commission, so it helps support the site. Thanks!

Get ACF Pro

Another essential plugin for site building. This isn't an affiliate link, it's just for convenience.

Get WP Codebox Pro

If you'd like an easier to use, and more advanced code management plugin (instead of just editing and making files yourself) then WP codebox pro is for you. Adding php, js, and even SCSS. Pretty nice! Affiliate link below.

Blank Plugin

Sort of blank. It's made to be easy to use with the tutorials. Download and edit any way you see fit.
  1. I will definitely try this trick. I have dealt with this issue for years and I always tell customers to hit CTRL and F5 if on a PC (Command and R on a Mac, but I know that doesn’t work on Safari).

    • I was really happy when this trick worked! Hope you like it!

  2. Hi,’
    You can try the below option in your function.php. No need to rename and save.

    add_action( ‘wp_enqueue_scripts’, ‘my_theme_enqueue_styles’ );
    function my_theme_enqueue_styles() {
    wp_enqueue_style(‘main-styles’, get_template_directory_uri() . ‘/style.css’, array(), filemtime(get_template_directory() . ‘/style.css’), false);
    }

    • Hi Muhammad, That’s very interesting. Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

New tutorials

Auto-updating Year in Footer
Designing Beyond the Brief
Disable Gutenberg Editor on some ACF pages
ACF flexible content fields in Breakdance 2.4

Got a question? ask!

If you have any question about the content on this page, feel free to send me an email by clicking the button below.

newsletter? sign up!

Sign up to the newsletter for updates on tutorials, news, and offers.

Join the cypher!

An awesome membership program for Breakdance Builder users coupled with an inclusive, friendly community.

Got a question?

If you have a question about something on this page, send me an email, and hopefully I can answer, and we can solve it!