通过 ESI:include 设置 Cookie,如何?
我正在尝试使用 esi 在我的网站上创建忍者缓存。 这个想法是,该网站大部分是静态的,我只需要在用户是否登录时做一些花哨的事情。 所以我试图在页面A上放置一个,并在页面B的应用程序中设置触发器。
这样我可以将页面A缓存在varnish上,并让服务器处理页面B的小工作。
但是cookie我在页面 B 上设置的内容没有转发到页面 A 的标题并且不起作用=/
我尝试这样做可能吗?
我可以使用ajax,但在将页面发送给用户之前在服务器内部执行此操作对我来说似乎更正确。
ps:我无法创建esi标签=/
Im trying to use esi to make a ninja caching on my site.
The idea is, the site is mostly static, I just need to do fancy stuff if the user is logged in or not.
So I was trying to put an on the page A, and set triggers in the application at page B.
This way I could cache the page A on varnish, and let the server deal with the small work that is page B.
But the cookies I've seted on page B were not forwarded to headers of page A and didn't work =/
Is this that Im trying to do possible?
I could use ajax, but doing this inside the server, before sending the page to the user seems more correct to me.
ps: I can't create an esi tag =/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法通过 esi include 设置 cookie,因为 esi 是由 varnish 请求的,而不是由客户端请求的。
您可以做的是通过 ESI 添加 javascript 标签或跟踪像素,然后以这种方式设置您的 cookie。或者您可以反转您正在做的事情,让您的主网络服务器请求设置 cookie 并执行您的用户操作,然后包含 ESI 以获取不需要 cookie 的内容。
You can't set cookies via an esi include because esi's are requested by varnish and not by the client.
What you can do is include a javascript tag or tracking pixel via ESI and then set your cookies that way. Or you could reverse what you're doing, make your main webserver request set cookies and do your user stuff then include an ESI to get the content which doesn't need cookies.