Reputation: 105
I have a laravel 5.2 app. My problem comes every time I update my website, I have all my clients calling me because something is not working, and the problem is because some .js and .css are in the cache, and I have to explain them how to erase the cache.
What's the best solution?, How is the tag to tell the browsers to not cache my .js or .css (or some of them, specified)?.
Thank you
Upvotes: 0
Views: 1635
Reputation: 6656
In laravel there's a versioning for stylesheets and scripts. Use laravel-elixir
can be found here.
If version only css stylesheet then you can use like:
elixir(function(mix) {
mix.version('css/all.css');
});
and you will have something like this all-16d570a7.css
If you want multiple files like css and js:
elixir(function(mix) {
mix.version(['css/all.css', 'js/app.js']);
});
And finally to run this versions you can simply enter the command below in your console:
gulp
or to be more specific gulp version
.
Hope this could help.
Upvotes: 1
Reputation: 1379
The way of making the browser will not save cache is by creating a new version for the source each time any user get to the web page.
The cache-buster query string can be updated so that the browser doesn’t recognise the file in it’s cache and downloads a new version.
I found a great information in the cache boosting link.
If you are using apache that link may be also very helpful.
Upvotes: 1
Reputation: 4937
You can version your JS and CSS when including them in your HTML by adding a version to the tag, such as <link rel="stylesheet" href="style.css?v=3.4.1">
When you make a change to the CSS or JS, change the version, and anyone visiting the page will load the new version instead of relying on the browser cache.
If you are using elixir with Laravel there are options included for versioning and cache-busting https://laravel.com/docs/5.3/elixir#versioning-and-cache-busting
Upvotes: 2