简体   繁体   English

缓存HTML的最佳做法是什么? 应该避免吗?

[英]What are the best practices for caching HTML? Should it be avoided?

I have been working on a few factors to optimize my webpages. 我一直在研究一些优化我的网页的因素。 I have optimized the delivery of everything else and now I am thinking about making some optimization related to the HTML. 我已经优化了其他所有内容的交付,现在我正在考虑进行一些与HTML相关的优化。

Since HTML can change frequently I was thinking caching it would be counter productive or an overkill but I know exactly when my HTML is going to change ( it changes every six hours). 由于HTML可以经常更改我认为缓存它会适得其反或过度杀戮我确切知道我的HTML何时会发生变化(每六个小时更改一次)。 Is caching my webpage for lets say 1 or 2 hours worth it? 缓存我的网页让我们说值1或2小时值得吗? What are some best practice that I should follow in case I decide to cache HTML? 如果我决定缓存HTML,我应该遵循哪些最佳做法?

For most smaller to midsize web sites, I would think this would be overkill. 对于大多数中小型网站,我认为这样会有点过分。

In order to determine how much time is being saved, the question is: how large is a given page on a site, and how often will people be clicking between pages? 为了确定节省了多少时间,问题是:网站上给定页面的大小,以及人们在页面之间点击的频率是多少? (Or, for that matter, are your users on particularly slow connections?) Unless the pages are very large, or people are spending a lot of time clicking between pages, the time spent loading the pure HTML should not be especially significant. (或者,就此而言,您的用户连接速度特别慢吗?)除非页面非常大,或者人们花费大量时间在页面之间进行点击,否则加载纯HTML所花费的时间并不是特别重要。

The CSS and JavaScript, sure, that makes sense to cache, but I believe most browsers handle that caching automatically. 当然,CSS和JavaScript对缓存有意义,但我相信大多数浏览器会自动处理缓存。 But loading HTML content is a relatively quick process; 但加载HTML内容是一个相对快速的过程; unless you are using a vast amount of HTML-generated graphics or other items (eg HTML5's SVG) I can't see much need to store that for later. 除非你使用大量的HTML生成的图形或其他项目(例如HTML5的SVG),否则我看不太需要将其存储起来供以后使用。

Think about how your users browse your sites - will they be visiting each page only a few times, or is your site built in such a way that they have to keep clicking back and forth between pages? 考虑一下您的用户如何浏览您的网站 - 他们只会访问每个网页几次,或者您的网站是否必须在网页之间来回点击?

Any site that would have people clicking back and forth sufficiently often to merit this might benefit from being built as a single-page application (SPA). 任何让人们经常来回点击以获得此功能的站点都可以从构建为单页应用程序(SPA)中受益。 If people are clicking back and forth enough that caching HTML becomes a serious concern, it might be better to think of those as different parts of one page. 如果人们来回点击足以使缓存HTML成为一个严重问题,那么将它们视为一个页面的不同部分可能会更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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