通过ESI设置Cookies:包括,如何? [英] Setting Cookies via ESI:include, how?

查看:80
本文介绍了通过ESI设置Cookies:包括,如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用esi在我的网站上进行忍者缓存. 这个想法是,该网站通常是静态的,如果用户未登录,我只需要做一些花哨的事情即可. 因此,我试图在页面A上放置一个,并在页面B的应用程序中设置触发器.

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.

这样,我可以将页面A缓存在清漆上,并让服务器处理页面B上的小工作.

This way I could cache the page A on varnish, and let the server deal with the small work that is page B.

但是我在页面B上设置的cookie没有转发到页面A的标题,并且不起作用=/

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?

我可以使用ajax,但是在将页面发送给用户之前在服务器内部执行此操作对我来说更正确.

I could use ajax, but doing this inside the server, before sending the page to the user seems more correct to me.

ps:我无法创建esi标签=/

ps: I can't create an esi tag =/

推荐答案

您无法通过esi include设置cookie,因为esi是由清漆而不是由客户端请求的.

You can't set cookies via an esi include because esi's are requested by varnish and not by the client.

您可以做的是添加一个javascript标记或通过ESI跟踪像素,然后以这种方式设置您的Cookie.或者,您可以撤消正在做的事情,使主要的Web服务器请求设置cookie,然后处理用户的事情,然后添加ESI以获取不需要cookie的内容.

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.

这篇关于通过ESI设置Cookies:包括,如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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