在plone.htmlhead 将 JSS 与 CSS 分离

发布于 2024-08-24 16:24:49 字数 209 浏览 6 评论 0原文

我在一个需要性能调整的项目中使用 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 技术交流群。

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

发布评论

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

评论(5

爺獨霸怡葒院 2024-08-31 16:24:49

我的同事找到了解决方案:

plone.htmlhead 是由产品 plone.app.layout 注册的视图,它加载其他三个视图:

  • plone.resourceregistries.styles
  • plone.resourceregistries.scripts
  • plone.resourceregistries.kineticstylesheets

我将以下内容放在 HEAD 处标签:

<div tal:replace="structure provider:plone.resourceregistries.styles" />

底部有以下内容:

<div tal:replace="structure provider:plone.resourceregistries.scripts" />
<div tal:replace="structure provider:plone.resourceregistries.kineticstylesheets" />

完成! 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:

  • plone.resourceregistries.styles
  • plone.resourceregistries.scripts
  • plone.resourceregistries.kineticstylesheets

I put the following at the HEAD tag:

<div tal:replace="structure provider:plone.resourceregistries.styles" />

And the following at the bottom:

<div tal:replace="structure provider:plone.resourceregistries.scripts" />
<div tal:replace="structure provider:plone.resourceregistries.kineticstylesheets" />

Done! the CSSs will be located at the page's top and the JSs at page's bottom

飘逸的'云 2024-08-31 16:24:49

您通常不必在 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 :)

在你怀里撒娇 2024-08-31 16:24:49

这是 Products.ResourceRegistries 的某些最新版本中的已知错误。此问题已在 2.02b 版本中修复。您可以将该版本固定在构建中:

[versions]
    ...
    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:

[versions]
    ...
    Products.ResourceRegistries == 2.02b
    ...

then, re-run buildout and this issue goes away.

極樂鬼 2024-08-31 16:24:49

上面用 3 个 viewlet 替换 plone.htmlhead 的建议并不完全适合我,因为我丢失了页面标题(不利于 SEO)。我假设页面标题通常也包含在 plone.htmlhead 中。

更好的解决方案似乎是使用上面建议的较新的 Products.ResourceRegistries,只是构建线略有错误。以下对我有用:

[版本]

<前><代码>...
产品.ResourceRegistries=2.0b3
...

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 :

[versions]

...
Products.ResourceRegistries=2.0b3
...
苍景流年 2024-08-31 16:24:49

在 head 标签中,

<div tal:replace="structure provider:plone.resourceregistries.styles" />

我还添加了

<title tal:define="page_title python: context_state.object_title()"
       tal:content="page_title">page title</title>

....
但事实上我已经丢失了所有与关键字相关的meta标签!

In the head tag in addition of

<div tal:replace="structure provider:plone.resourceregistries.styles" />

I've put

<title tal:define="page_title python: context_state.object_title()"
       tal:content="page_title">page title</title>

....
but in fact I have lost all the meta tags related to the keywords !

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