当刷新我的主题缓存时,Drupal 如何将模块 css 文件添加到合并文件中?

发布于 2024-12-13 16:38:03 字数 342 浏览 0 评论 0原文

当我清除我的主题注册表时,Drupal 会运行并构建一个漂亮的综合 css 文件,但它针对不同的节点/页面类型执行此操作,以便我获得所述文件存在的多个实例。我在另一个 我问的问题(并回答了),但我的问题是,Drupal 如何推断它需要添加到合并版本中的 css 文件?必须有许多不同的地方来控制哪些模块出现在特定节点上,那么什么构成了正在构建的另一个 css 文件的规则呢?

When I clear my theme registry Drupal runs off and builds out a nice consolidated css file, but it does this for different node/page types so that I get several instances of said file existing. I mentioned this in another question I asked (and answered), but my question is, how does Drupal deduce what css files it needs to add to the consolidated version? There must be numerous different places that control what modules appear on a particular node, so what constitutes a rule for another css file being built?

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

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

发布评论

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

评论(1

一花一树开 2024-12-20 16:38:03

好吧,这不是一个简单的函数链,但我想我已经做到了......

每次“刷新”页面(即从头开始构建,而不是从缓存提供)时,所有 CSS 文件都会添加 在页面构建期间,drupal_add_css() 被聚合并保存到单个文件中,该文件作为该页面的 标记返回。

drupal_add_css() 中的以下行决定聚合 CSS 文件的名称:

$filename = 'css_'. md5(serialize($types) . $query_string) .'.css';

在此上下文中的 $types 是使用 添加的所有 CSS 文件的数组drupal_add_css() 在当前页面构建期间。聚合 CSS 的文件名包含一个 $types 序列化字符串,这本质上意味着添加与该 CSS 文件相同的 CSS 文件的任何其他页面都将收到完全相同的文件名,从而加载相同的 CSS文件。

所以基本上,聚合函数会针对每个页面构建运行,因此每次添加到该页面的所有 CSS 都会被聚合。如果某些页面碰巧使用相同的模块,那么它们将自动提供与上面 PHP 代码片段中定义的相同的 CSS 文件。当您将其与页面缓存结合使用时,您将获得在不同页面上的 HTML 源代码中找到的结果。

希望这是有道理的!

Well that wasn't an easy chain of functions to follow but I think I've got there...

Every time a page is 'refreshed' (i.e. built from scratch, not served from cache) all CSS files added with drupal_add_css() during that page build are aggregated and saved to a single file that is returned as the <link> tag for that page.

The following line in drupal_add_css() decides what the aggregated CSS file's name will be:

$filename = 'css_'. md5(serialize($types) . $query_string) .'.css';

$types in this context is an array of all of the CSS files added using drupal_add_css() during the current page build. The filename for the aggregated CSS contains a serialised string of $types, which essentially means that any other page that adds the same CSS files as that one will receive exactly the same file name and thus load the same CSS file.

So basically, the aggregation function is run for every single page build so all CSS added to that page will be aggregated every time. If certain pages happen to use the same modules then they will automatically be served the same CSS file as defined in the PHP snippet above. When you combine that with page caching you get the results you find in the HTML source on the different pages.

Hope that makes sense!

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