简体   繁体   中英

Is there a html tag that can tell browser to cache my html and or css file?

So far I read about js and css browser caching need to be enabled by things like server side setting .htaccess. Is there no way to just add a html tag / config on the html page or js config to tell browser to do that (ie cache my js and css for certain period of time or indefinitely)?

No. You can ask a browser not to cache a page, but the browser may not have the storage space available to be able to cache your page. If it's secure to do so, and the browser has the space available, it will ordinarily cache the page unless asked not to. By the same manner, you can place limits on the maximum time a page should be cached for, but not a minimum time.

Even requesting not to cache pages should be done via an HTTP header (eg by .htaccess) though, and not through a <meta> element. The cache control meta elements are obsolete in HTML5, because only browsers will read them. Which means that network proxies won't know not to cache the files.

Furthermore. as @dpix points out in the comments, a <meta> element is only good for HTML files, and not other resources.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM