通过 ESI:include 设置 Cookie,如何?

发布于 2024-10-04 23:04:30 字数 296 浏览 0 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

感悟人生的甜 2024-10-11 23:04:30

您无法通过 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文