Varnish ESI 多个片段,单个请求?
我的任务是改善 WordPress 多站点相当大的部署的页面服务时间。
我正在考虑使用 varnish 进行全页内容缓存,并使用它的 ESI 功能来包含与用户登录状态相关的动态内容,还通过使用与自定义标头匹配的 varnish 清除列表来处理应用程序中的缓存失效博客的 ID 或其他一些包含文章 ID 和/或用户 ID 的自定义标头。
我想知道是否有人想出一种方法,通过 ESI 包含多个页面片段,同时将它们分组到来自后端的单个响应中(例如,我们必须在菜单中显示用户名,并在侧边栏中显示自定义用户小部件,页面的其余部分是静态的并由 varnish 缓存,要求我向后端发出两个请求,以便检索两个片段并将它们放置在正确的位置,而在后端我可以轻松地为这两个片段生成 HTML 代码。一个单次运行并将其返回清漆进行处理)
I am tasked with improving page serving time for a rather big deployment of wordpress multisite.
I am considering using varnish for full page caching of content and using it's ESI abilities to include the dynamic content associated with the logged-in state of a user, also handling cache invalidation in the application by using varnish purge list that matche a custom header of the blog's id or some other custom headers containing article ids and/or user ids.
I'd like to know if anyone ever figured a way of including multiple page fragments through ESI while grouping them in a single response from the backend (eg. we must display the user's name in the menu and a custom user widget in the sidebar, the rest of the page is static and cached by varnish. ESI mandates that I make two requests to the backend in order to retrieve the two fragments and place them at their proper location while at the backend i could easily generate the HTML code for both in a single run and return it to varnish for processing)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
让 ESI 在一个请求中返回 HTML 块,并包装在一些 Javascript 逻辑中,触发将各种 HTML 字符串放置在适当的位置,怎么样?有点奇怪,但解决了您的问题,而且实施起来应该不会很难。
移动部分较少的另一个选择是将通过 ESI 获得的所有 HTML 块分组到页面中的单个点(例如底部),然后使用 CSS 将它们绝对定位在页面上您想要的位置。
What about having the ESI return the HTML chunks in one request and wrapped in some Javascript logic that fires to place the various HTML strings in the appropriate places? A little odd, but solves your problem, and shouldn't be very difficult to implement.
Another option with fewer moving parts would be to group all the HTML chunks you'd be getting via the ESI include at a single point in the page, say the bottom, and then use CSS to absolutely position them where you want on the page.