简体   繁体   English

使用cloudflare缓存动态页面

[英]Using cloudflare to cache dynamic pages

We have a number of pages where the only dynamic content is the user info (Name, profile link, # of items in shopping bag) which is at the top corner. 我们有许多页面,其中唯一的动态内容是用户信息(名称,配置文件链接,购物袋中的物品数),该信息位于右上角。 These pages can take upto a second or more to load sometimes. 这些页面有时可能需要一秒钟或更长时间才能加载。

We are thinking of changing the pages so that the entire HTML page is cached using Cloudflare, then when it's displayed, JavaScript will check for the presence of a cookie name "Username" and "CartCount" and update the profile accordingly, or if the cookie is not available, show the customary login icon. 我们正在考虑更改页面,以便使用Cloudflare缓存整个HTML页面,然后在显示页面时,JavaScript将检查cookie名称“ Username”和“ CartCount”的存在并相应地更新配置文件,或者是否更新cookie不可用,请显示常规登录图标。

Is this method feasible and are there any security precautions that need to be taken? 此方法是否可行,是否需要采取任何安全预防措施?

Not only it's feasible, it's actively used by some of the big websites - eg. 它不仅可行,而且还被一些大型网站积极使用-例如。 Airbnb, TripAdvisor. Airbnb,TripAdvisor。

You may notice that if you open these websites (and many others) at first it looks like you are not logged in, and then later DOM updates with your user name. 您可能会注意到,如果首先打开这些网站(以及许多其他网站),则好像您尚未登录,然后再使用用户名更新DOM。

The only issue I see is CSRF tokens - if you cache the pages, your tokens will be outdated and not longer useful. 我看到的唯一问题是CSRF令牌-如果您缓存页面,则令牌将过时并且不再有用。 You will have to turn off CSRF checks for your AJAX requests and sign in page. 您将必须为您的AJAX请求关闭CSRF检查并登录页面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM