• How to disable any cache to a javascript file?

    preventing the w3 make any kind of cache for that file and always show no cached version.

    Thanks

Viewing 1 replies (of 1 total)
  • Ashok

    (@bappidgreat)

    @fjps3701, is that something because your js file is changed frequently? If so, you can use version number as query param when the js file is enqueued, so every time there is a change in the file, the version number will be changed. Once version (query value) is changed, new version will be loaded. Here is an example:

    
    /**
     * Never worry about cache again!
     */
    function my_load_scripts($hook) {
     
        // create my own version codes
        $my_js_ver  = date("ymd-Gis", filemtime( plugin_dir_path( __FILE__ ) . 'js/custom.js' ));
        $my_css_ver = date("ymd-Gis", filemtime( plugin_dir_path( __FILE__ ) . 'style.css' ));
         
        // 
        wp_enqueue_script( 'custom_js', plugins_url( 'js/custom.js', __FILE__ ), array(), $my_js_ver );
        wp_register_style( 'my_css',    plugins_url( 'style.css',    __FILE__ ), false,   $my_css_ver );
        wp_enqueue_style ( 'my_css' );
     
    }
    add_action('wp_enqueue_scripts', 'my_load_scripts');
    

    Have a good day!

    Cheers
    Ash

Viewing 1 replies (of 1 total)
  • The topic ‘How to prevent caching of my Javascript file?’ is closed to new replies.