Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #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’ );

    #553488

    I 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’ );

    #553493

    Hi,

    Great, glad you got it fixed. Please let us know if you should need any further help on the topic.

    Regards,
    Rikard

    #553536

    Hey @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 ?
    Thanks

    #554200

    @pako69

    yes. 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.php

    You still need to ask your customer to clear the browser cache ONCE after this update. But no more clear is needed after this.

    #554202

    Hi @boscotwcheung,

    Thanks for replying :-)

    Regards,
    Rikard

    #1281779

    Hi, 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

    #1282153

    Hi 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

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.