Search code examples
javascripthtmlbrowser-cachecache-control

How to not tell browser not to save cache


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


Solution

  • 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