在加载页面之前执行代码的最佳方式是什么

发布于 2024-10-13 00:11:15 字数 553 浏览 4 评论 0原文

基于我之前的问题,在企业版 Magento 中,如果您计划启用全页缓存,那么使用任何可用的控制器事件似乎不是一个好主意。看来您只想在对实际页面执行某些操作时才使用这些事件。

然而,我们为 Magento 构建了一些扩展,在 controller_action_predispatch 上,我们有一个观察者,从那里我们可以获取 URL 中的一个参数,如果设置正确,我们可以从那里执行一些附加功能。例如,我们这样做是为了让客户可以将促销代码放入电子邮件营销活动的网址中,当他们单击该链接时,促销代码就会附加到客户的报价中。我们必须在页面加载之前查找参数并执行我们的操作。

但现在有了这个整页缓存,它就无法正常工作了。那么,不使用观察者来执行此操作并仅扩展代码可能会更好吗?或者有更好的观察者可以做到这一点。我们之前尝试使用 HTTP 发送响应,但得到的结果好坏参半。

Based on my previous question, in Enterprise Edition Magento it doesn't appear to be a good idea to use any of the available controller events if you are planning on having the full page caching enabled. It looks to be you only want to use these events if you are doing something with the actual page.

However, we have built some extensions for Magento that on controller_action_predispatch, we have an observer and from there we grab a parameter in the URL and if it is set correctly we do some additional functionality from there. For example, we have made it so a client can put promo codes in urls for email campaigns and when they click that link it is attached to the customer's quote. We have to look for the parameter before the page is loaded and do our thing.

But now that there is this full page caching it isn't working correctly. So is it probably better to not do this with an Observer and just extend the code? Or are there better Observers to do this with. We tried to use HTTP send response before one and got mixed results.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

美羊羊 2024-10-20 00:11:15

如果您找不到合适的活动,请请求一个,或自己创建一个。也许扩展Enterprise_PageCache_Model_Processor并检查它返回的内容,如果非空则触发新事件。然后用一个观察者观察这两个事件。

If you cannot find a suitable event then request one, or create it yourself. Perhaps extending Enterprise_PageCache_Model_Processor and checking to see what it returns, if non-empty then trigger the new event. Then watch both events with a single observer.

谁许谁一生繁华 2024-10-20 00:11:15

如果您想保留对 controller_action_predispatch 事件的投资并保留代码的 Magento 框架,您可以执行以下操作。

  1. 将 URL 参数添加到缓存键中。这样,FPC 将提供参数可以触发的页面的不同版本,同时仍然提供缓存的好处。请参阅此博客文章,了解创建自己的示例PageCache 容器并覆盖缓存键。

  2. 从 FPC 中排除这些控制器。显然,只有当受影响的控制器是整个站点的子集时,这才有效,否则您将不会获得任何缓存优势。

干杯,
京东

If you want to keep your investment in the controller_action_predispatch events and stay in the Magento framework for your code, you could do a couple of things.

  1. Add the URL param into the cache key. That way the FPC will serve the different versions of the page that the param can trigger while still giving the benefit of caching. Refer to this blog post for an example of creating your own PageCache container and overriding the cache key.

  2. Exclude those controllers from FPC. Obviously this is only valid if the controllers affected are a subset of the overall site, otherwise you won't get any caching benefit.

Cheers,
JD

等你爱我 2024-10-20 00:11:15

也许 auto_prepend_file 指令可以帮助?

Maybe auto_prepend_file directive could help?

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