Web前端缓存网站的最佳做法? [英] Web front end caching best practices for site?

查看:119
本文介绍了Web前端缓存网站的最佳做法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

摘要



当我在查找stackoverflow和网络时,发现缺乏一个关于缓存高性能的最佳做法的良好文档网站使用会话。如果我们可以分享一些基本的构建块,特别是关于缓存的想法,这将是有帮助的。为了讨论的目的,我正在避免memcache,并专注于缓存静态和完全生成的页面。



所以要设置场景,想象一下网络服务器(比如说nginx),反向代理(比如说清漆),应用服务器(无论如何),数据库服务器(mysql)。



匿名




  1. 静态项(gif / jpg等)

  2. 半动态(js / css)

  3. 动态



登录




  1. 静态

  2. 半动态(js / css)

  3. 动态

一般来说,所有的Anon都应该是可缓存的,大部分的Logged In(忽略动态,没有ESI现在)



Anon#1




  • 设置远程过期

  • 设置ETag(如果可能)

  • 缓存控制:max-age = 315360000



    • Anon#2
      (具有反向代理缓存的结果,如果动态生成的其他Anon#1规则适用)




      • 缓存控制:public,s-maxage = 3000



      Anon#3




      • 缓存控制:public,s-maxage = 300



      登录#1




      • 设置远端Expires

      • 如果可能,设置ETag

      • 缓存 - 控制:max-age = 315360000



      登录#2
      代理缓存结果如果动态生成的其他登录#1规则适用)




      • Cache-Control:public,s-maxage = li>


      登录#3




      • 缓存控制:s-maxage = 0,必须重新生效



      您的建议是什么?我会更新帖子作为答案进来。

      解决方案

      我最好的答案是,你有很多选择所有的静态文件,可以以自己的方式产生大量收益,每个都在特定场景中有所收益,因此根据您的具体需要对专业人员和顾问负责。



      然而,大多数人忽视的是他们的动态内容,确实缓存数据库结果等都是很棒的,但是实际上还是启动了PHP / ASP或其他任何解析引擎。



      如果您查看wordpress的超级缓存插件,您将会注意到,它可以实际准备您的html作为静态文件。不仅如此,它也使得gzip副本,并使用重写规则检查这些文件的存在是启动解析器的适当替代方法。这显然会给你最好的结果,因为它不仅可以节省您的处理时间,还可以节省带宽。



      如果您想查看性能差异,请比较 c code code code $ c

      显然,您需要注意这种缓存,但是如PHP之类的解释器替换全页缓存可能非常有用。


      Summary

      As I'm looking on stackoverflow and around the net, I find that there is a general lack of good documentation on best practices for caching a high performance site that uses sessions. It would be helpful if we can share some ideas around some basic building blocks particularly around caching. For the purpose of this discussion, I'm avoiding memcache and focusing on the caching of static and pages that are fully generated.

      So to set up the scenario, imagine a web server (say nginx), reverse proxy (say varnish), app server (whatever), db server (say mysql).

      Anonymous

      1. Static items (gif/jpg etc.)
      2. Semi dynamic (js/css)
      3. Dynamic

      Logged In

      1. Static
      2. Semi dynamic (js/css)
      3. Dynamic

      Generally speaking, all of the Anon should be cacheable and most of Logged In (ignore dynamic, no ESI for now).

      Anon #1

      • Set far-off Expires
      • Set ETag if possible
      • Cache-Control: max-age=315360000

      Anon #2 (have the reverse proxy cache the result if dynamically generated else Anon #1 rules apply)

      • Cache-Control: public, s-maxage=3000

      Anon #3

      • Cache-Control: public, s-maxage=300

      Logged In #1

      • Set far-off Expires
      • Set ETag if possible
      • Cache-Control: max-age=315360000

      Logged In #2 (have the reverse proxy cache the result if dynamically generated else Logged In #1 rules apply)

      • Cache-Control: public, s-maxage=3000

      Logged In #3

      • Cache-Control: s-maxage=0, must-revalidate

      What are your suggestions? I'll update the post as answers come in.

      解决方案

      My best answer to this, is that you have plenty of options for all of the static files, which can produce lots of gains in their own way, each beneficial in a specific scenario, so weigh up the pro's and cons according to your specific need.

      However, what most people neglect to think about is their dynamic content, sure caching db results and the like are great, but still involve actually starting up the parsing engine of PHP/ASP or whatever.

      If you look at the super-cache plugin for wordpress, you will note that it has the ability to actually prepare your html as static files. Not only that, but it also makes a gzip copy, and uses rewrite rules to check for the existence of these files as an appropriate alternative to starting up the parser. This is obviously going to give you the best result, as it is not only saving your processing time, but also bandwidth.

      If you want to see the performance disparity, compare the apachebench results of <?php die('hello world'); with serving a static .html page.

      Obviously you would need to be careful with this sort of caching, but it can be very useful to replace fullpage caching from inside an interpreter like PHP.

      这篇关于Web前端缓存网站的最佳做法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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