EvanAgee / vuejs-wordpress-theme-starter

A WordPress theme with the guts ripped out and replaced with Vue.
https://vuewp.com/
1.6k stars 281 forks source link

Cache busting #31

Closed mercs600 closed 5 years ago

mercs600 commented 5 years ago

Hi @EvanAgee, great job ;-) I did not use it starter yet, but I see potential problem with cache busting.

https://github.com/EvanAgee/vuejs-wordpress-theme-starter/blob/master/functions.php

    wp_enqueue_script('blankslate/app.js', get_template_directory_uri() . '/dist/scripts/app.js', null, null, true);

I see you attach file without any specific version. What in case when you rebuild some js/css files ? How did you resolve it ?

demyxco commented 5 years ago

@mercs600 you can try adding a query at the end like so:

wp_enqueue_script('blankslate/app.js', get_template_directory_uri() . '/dist/scripts/app.js?v='.time(), null, null, true);

mercs600 commented 5 years ago

@manacim this way your assets won't be cached, because each request will generate new timestamp. Not good for production ;-(

EvanAgee commented 5 years ago

Thanks for the heads up @mercs600 I actually normally do something like this for scripts, just haven't added it to this repo yet.


wp_enqueue_script(
    'app-js,
    get_stylesheet_directory_uri() . '/dist/index.min.bundle.js',
    null,
    filemtime(get_stylesheet_directory() . '/dist/index.min.bundle.js'),
    true
  );
mercs600 commented 5 years ago

@EvanAgee Thanks! Probably this method solves the problem ;-)