在plone.htmlhead 将 JSS 与 CSS 分离
我在一个需要性能调整的项目中使用 Plone 3.1.7。其中一项调整要求 CSS 应位于页面顶部,JS 应位于底部。然而,两者都位于
<div tal:replace="structure provider:plone.htmlhead" />
main_template 中。我该如何分割这些?
提前致谢
I'm using Plone 3.1.7 in a project that needs performance tweaks. One of the tweaks requests that CSS should be at the top of page and the JS should be at the bottom. However both are located at
<div tal:replace="structure provider:plone.htmlhead" />
In main_template. How do I split these ones?
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我的同事找到了解决方案:
plone.htmlhead 是由产品 plone.app.layout 注册的视图,它加载其他三个视图:
我将以下内容放在 HEAD 处标签:
底部有以下内容:
完成! CSS 将位于页面顶部,JS 位于页面底部
My workmates have found the solution:
plone.htmlhead is a viewlet registered by the product plone.app.layout that loads other three viewlets:
I put the following at the HEAD tag:
And the following at the bottom:
Done! the CSSs will be located at the page's top and the JSs at page's bottom
您通常不必在 Plone 中执行此操作,因为它被设置为异步触发 JS,因此它不应该阻止任何渲染(这就是性能提示的内容)。
如果您直接在模板中插入内容,情况可能会发生变化 - 但默认设置会做正确的事情,除非我误解了这里的问题(可能是这种情况:)
You usually don't have to do this in Plone, as it is set up to trigger the JS asynchronously, so it shouldn't block any rendering (which is what the performance tip is about).
If you insert things directly in the template, things may change — but the default setup does the right thing, unless I'm misunderstanding the question here (which may be the case :)
这是 Products.ResourceRegistries 的某些最新版本中的已知错误。此问题已在 2.02b 版本中修复。您可以将该版本固定在构建中:
然后重新运行构建,此问题就会消失。
This was a know bug in some recent versions of Products.ResourceRegistries This issue is fixed in the 2.02b release. You can pin that version in your buildout:
then, re-run buildout and this issue goes away.
上面用 3 个 viewlet 替换 plone.htmlhead 的建议并不完全适合我,因为我丢失了页面标题(不利于 SEO)。我假设页面标题通常也包含在 plone.htmlhead 中。
更好的解决方案似乎是使用上面建议的较新的 Products.ResourceRegistries,只是构建线略有错误。以下对我有用:
The suggestion above to replace plone.htmlhead split with 3 viewlets didn't entirely work for me, as I lost the page title (not good for SEO). I assume the page title is also normally included by plone.htmlhead.
The better solution seems to be to use the newer Products.ResourceRegistries suggested above, except that the buildout lines are slightly wrong. The following worked for me :
在 head 标签中,
我还添加了
....
但事实上我已经丢失了所有与关键字相关的meta标签!
In the head tag in addition of
I've put
....
but in fact I have lost all the meta tags related to the keywords !