HTML - 缓存控制最大年龄 [英] HTML - Cache control max age

查看:146
本文介绍了HTML - 缓存控制最大年龄的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将总是最新的网站内容呈现给用户,但也要快速加载。通过研究,我发现有人建议使用缓存来加速加载。

那么我需要添加到我的网站才能在3天后覆盖缓存以显示最新内容?

有很多方法可以做到这一点 - 但你需要考虑到你需要缓存什么以及不需要什么。最大的速度提升可能来自确保您的资产(css,images,javascript)被缓存,而不是html本身。然后,您需要考虑各种因素(这些资产多久改变一次,您将如何强制用户下载文件的新版本才能更改它?)。

通常,作为网站发布过程的一部分,新文件(更新文件)会被赋予新文件名以强制用户浏览器重新下载文件,但这只是一种方法。



你应该看看apache mod_expire,以及使用.htaccess文件设置资产到期时间的能力。

http://www.google.com/?q=apache+cache+control+ htaccess#q = apache + cache + control + htaccess

I'ld like to present always the latest website content to the user but also have it fast loaded. By researching I came across postings people suggesting to use the cache for speeding up loading.

So what do I need to add to my website to "overwrite" the cache after 3 days to display the latest content?

解决方案

There is more than one way to do this - but you need to consider exactly what you need to cache and what you don't. The biggest speed increases will likely come from making sure your assets (css, images, javascript) are cached, rather than the html itself. You then need to look at various factors (how often do these assets change, how will you force a user to download a new version of the file of you do change it?).

Often as part of a sites release process, new files (updated files) are given a new filename to force the users browser to redownload the file, but this is only one approach.

You should take a look at apache mod_expire, and the ability to set expiry times for assets using the .htaccess file.

http://www.google.com/?q=apache+cache+control+htaccess#q=apache+cache+control+htaccess

这篇关于HTML - 缓存控制最大年龄的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆