-
AuthorPosts
-
December 15, 2015 at 8:13 am #552834
Hi,
The css and javascript files are always being cached by the browser even I disabled the cache from my browser in the debugger. And this always happening in my customer as well. Sometimes it is hard to ask them to clear the browser cache.
I tried to add a random number parameter to the style.css in header.php but I found the wp_head() function will load the theme style anyway. It makes the style.css loaded 2 times. One is the cached file and the other one in random number parameter which is the most updated. However, it makes conflict sometimes as the cached css can overwrite the most updated css. So, I tried to see if there is any hack to the wp_head function. I added the following code to the function.php. But I still see the same css file loaded 2 times with one in version number and the second one in filen time. How can I disable the default one to be loaded in wp_head?
function css_versioning() {
wp_enqueue_style( ‘style-css’, get_stylesheet_directory_uri() . ‘/style.css’ , false,filemtime( get_stylesheet_directory() . ‘/style.css’ ), ‘all’ );
}
add_action( ‘wp_enqueue_scripts’, ‘css_versioning’ );December 16, 2015 at 7:43 am #553488I fixed the problem by adding custom.css into the child theme and add the following to the function.php
function css_versioning() {
wp_enqueue_style( ‘custom-css’, get_stylesheet_directory_uri() . ‘/custom.css’ , false,filemtime( get_stylesheet_directory() . ‘/custom.css’ ), ‘all’ );
}
add_action( ‘wp_enqueue_scripts’, ‘css_versioning’ );December 16, 2015 at 7:53 am #553493Hi,
Great, glad you got it fixed. Please let us know if you should need any further help on the topic.
Regards,
RikardDecember 16, 2015 at 10:25 am #553536Hey @boscotwcheung :)
I’m facing the same problem as you and I’m tired to tell my customers to empty the browser cache.
So, you are using a child theme, but if I understand what you’ve done :
– your child style.css is empty (I mean no css, but just the include to the enfold original style.css)
– you create a new file called custom.css in the child directory and put all your css in it ?
ThanksDecember 17, 2015 at 5:40 am #554200yes. So, it will
1. load an empty style.css by default in wp_head function
2. load the custom css (with file time as parameter) ONCE with all my custom css on it by adding some code in function.phpYou still need to ask your customer to clear the browser cache ONCE after this update. But no more clear is needed after this.
December 17, 2015 at 5:50 am #554202February 17, 2021 at 4:27 pm #1281779Hi, I can’t get this to work. Ive been looking for a solution to this for a while as I am sick of having to tell clients to clear cache. Also obviously would like a way to know normal users are seeing the latest version. I have added the above code which does add a version number which is a good start but on my cached browsers it still shows the old version numbers?
So logged in (non cached) is showing the latest version /themes/thetheme/custom.css?ver=1613571623
where as the cached version is showing /themes/thetheme/custom.css?ver=1613570555 .Am I missing something?
thanks
February 19, 2021 at 7:20 am #1282153Hi dannhanks,
Did you make sure that you have activated the option to delete the old CSS and JS files under Enfold->Performance? If that doesn’t help, then please open a new thread and include WordPress admin login details in private so that we can have a closer look at your site.
Best regards,
Rikard -
AuthorPosts
- You must be logged in to reply to this topic.