Force JavaScript/CSS reload in WordPress themes

5 thoughts on “Force JavaScript/CSS reload in WordPress themes”

  1. Interesting way of handling it. I might have to check that out. Since I always try to bump the theme version when I make changes, I’ve been doing it based on theme version number like this:


    $foo = wp_get_theme();

    wp_enqueue_style( 'grid', get_stylesheet_directory_uri() . '/css/grid.css', array(), $foo['Version'], 'all' );

  2. Hey Tareq,

    I ran across another way to do this a while back and I thought about your post here.

    I like this way better for some cases. Especially because I’ve seen some super aggressive caching where the browser even caches assets with a query string in the URL. I’ve seen several cases where Chrome does this and people were seeing old versions of a site for days.

    This method does a rewrite that adds the last modified date to the filename that is returned and uses no query strings, ensuring things are cached and when updated they don’t stay cached when they’re not supposed to.

    http://w-shadow.com/blog/2012/07/30/automatic-versioning-of-css-js/

  3. Hola!

    And why not using just “time()” for the version in the wp_enqueue_script?

    wp_enqueue_script( ‘theme-script’, get_template_directory_uri() . ‘/js/scripts.js’, array(‘jquery’),time(), true );

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.