When coding HTML, browser doesn't always detec

2019-02-26 08:17发布

问题:

When I'm coding HTML and CSS and load the page in the browser to check changes, sometimes it doesn't update for a while. This obviously causes problems with incremental changes where it's hard to tell if it's changed to suit my latest change or not.

I was wondering if there was a way around this? Possibly a browser (or mode) which is especially for this situation that doesn't have this behaviour?

回答1:

Try Ctrl+F5 on Windows or Cmd+Shift+R on OSX, this will avoid your browser reading its cache when loading the page (at least when it's Chrome or Firefox)



回答2:

It is mostly because of browser cache.

Just a suggestion(You may find it useful, As an addition to other answers):

If you are on chrome then there is an option to disable cache while the dev toolbar is open. It works for me to ensure there is no caching while I am developing. (I keep my dev toolbar open all the time while developing so it works for me), Here is the screen shot.

Quote from chrome dev tools (https://developers.google.com/chrome-developer-tools/docs/settings)

General

Disable cache Will prevent the caching of resources ONLY for pages which have DevTools open. This will not disable caching if the DevTools are closed

.



回答3:

You could try deleting your browser cache and reloading the page. In case of CSS I also found sometimes I will need to load the CSS file separately in my browser and refresh it to update.



回答4:

Sounds like your browser cache, you can test this by clearing it or doing a "hard refresh" to confirm.

You will need to throw some no cache headers if you want to stop this permanently, you can do this from the web server or server-side code depending on your setup (see How to control web page caching, across all browsers?)



回答5:

On windows refresh with CTRL + F5. The browser will not show from cache. Also in developer tools you can tell it not load from cache



回答6:

Hmm could be a web server setting, caching request to your same resource. I used to see that a lot on tomcat with JSP. With tomcat we used to delete compiled classes ('work' folder), though, in your case with PHP you may check your server cache settings (files/sessions).

Example: "A typical web server, such as Apache, uses the time of file modification to inform a web browser of a requested page’s age, allowing the browser to take appropriate caching action. With dynamic web pages, the actual PHP script may change only occasionally; meanwhile, the content it displays, which is often fetched from a database, will change frequently."

Source : http://www.sitepoint.com/caching-php-performance/

Another workaround would be to touch (add a space and save) your PHP file when you want it to reload.