问题
Someone know how to force a page cache in the browser? I need to reload a page several times, and the browser isn't caching the page!
回答1:
If browser is not caching the page there's no much you can do than using one of them:
<meta http-equiv="Cache-control" content="public">
OR
<meta http-equiv="Cache-control" content="private">
You can't programatically override browser settings. It would be a security issue!
回答2:
Even if you have <meta http-equiv="Cache-control" content="public">
there are other factors to consider.
Note that some browsers have a file size limit for caching ... keep html below 25Kb if you can and external resources like css, js etc... below 1Mb, but for browser specifics see: here and here
You can check browser.cache.disk.max_entry_size
on some browsers and you can approximate the length with document.getElementsByTagName('html')[0].outerHTML.length
if it is not possible to precalculate the sizes of your files.
Your server needs to appropriately set "Last-Modified" and "Expires"
This will only increase the likelihood of caching if it is enabled though, not force it. You might consider using local storage if it is enabled and caching is not (some people will just disable caching altogether to cope with 1 particular site)
回答3:
You have to add this metatag :
<meta http-equiv="Cache-control" content="public">
来源:https://stackoverflow.com/questions/19059380/how-to-force-the-browser-to-cache-a-page-html