I’m hosting a website and everytime I change any CSS or JavaScript code, I need to clea navigation data from my browser to see the changes in the live website. Can I fix this somehow?
Besides clearing your cache after every changes, you can just let the browser update on its own.
I would not want to change this behavior, it would just make website load more slowly for you, and you would use more data every time you request a page
You can just use Ctrl+F5. This will refresh the page with cleaning cache
But whenever I make changes to the website, other people won’t see them until they clean the cache
But thats normal
Well, they will see the changes when the cache period expires, and that will be totally fine for 99% of your visitors. Most of them won’t visit your site too frequently, so by the time they come back again, the cache period will most likely be expired.
on my website https://lovebyte.eu.org I was having this same issue and the solution I came up with was to rename my index.html page to index.php
then in the head section where I load my css file I used this code
<link rel='stylesheet' href='/lovebug.css?<?php echo filemtime($_SERVER["DOCUMENT_ROOT"] . "/lovebug.css"); ?>' />
what this does is add “?” followed by the file creation time after the css file name which causes the browser to see a new file name when you update the css and the browser will reload and cache the changes
no need to refresh the page, works every time
I havent tried it with javascript files but it’ll probably work ?
Actually it fetches new resources if you add a query string (or it’s supposed to), but the general practice is to add something like that to force it to grab new resources (which sometimes it just doesn’t anyway). IMO adding the file hash to the file name (like webpack does) is a better solution, but it becomes annoying to maintain.
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.