Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force browser to clear cache when i upload a new version of code

I'm currently running a laravel with VueJs Web application. I made some changes to the css and released the new version a few days ago. Most of the css messed up because of browser cache.

Instead of asking users to force reload cache, which is not feasible , is there another way to force browser to retrieve the new version of files so that the changes are reflected?

Thank you!

like image 573
Shin Avatar asked Mar 04 '23 02:03

Shin


1 Answers

Yes, you can prevent the browser caching of your newly updated script by adding a version number at the end of the file.

<link 
    rel="stylesheet" 
    href="{{ asset('css/app.css?v='.filemtime(public_path('css/app.css'))) }}" 
/>

The same you can do with the js file as well.

the filemtime() method returns the file modification time, that only changes when you modify your css file.

like image 164
jogesh_pi Avatar answered Mar 05 '23 15:03

jogesh_pi