Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ivymasterman's avatar

How to clear cache in VueJS app?

I have a situation where I am asked to implement a function to clear cached files from the browser, upon app reload. The important thing is that the JS and CSS files need to be cleared, but cached images should remain.

I am using VueJS app on front, a SPA, and Laravel on backend.

Is there even a way to clear the cache programmatically? Can you set somehow headers, like "Cache-control", that tell the browser not to cache JS and CSS files at all, but keep the caching for images?

0 likes
3 replies
ivymasterman's avatar

I proposed the JS and CSS file versioning, but they had some problems with dockerized deployment of the app.

Somehow the versionings are properly set in the built stage, but during deployment, they are lost. Can not tell you more about it.

So the approach would be a "workaround" for the versioning. If the JS and CSS files can be cleared, and not cached, this would solve the problem. The constant JS and CSS refetch is not an issue, it is acceptable.

Pls help :)

martinbean's avatar

@ivymasterman You can’t programatically clear a browser’s cache. It’s the browser’s. Not yours.

You should address the actual problem instead of the symptoms. Look at why the versioning isn’t working on deploy. You should be generating asset URLs that contain a hash as a query string. Mix had a helper to output these versioned URLs. I’m sure Vite will too if you’re using that instead.

1 like

Please or to participate in this conversation.