我在 Pantheon 上托管了 Drupal 7 Open Atrium 2 站点。在做一些性能分析时,我查看了“网络”选项卡中的检查器,发现我有一个 404,以及一个 CSS 文件的加载需要很长时间。这个 css 文件本质上是域的链接。我不明白 Drupal 在何处或为何将这些“幻影”样式表链接添加到域中。
似乎某处有一个样式表数组,Drupal 正在抓取数组中的最后一个空白项并将其添加为样式表链接。在一种情况下,它为 css 缓存提供了一个相对链接“/”+“”+随机字符。在另一种情况下,它将数组中的空白项附加到站点域 mysite.pantheon.com + ""+ 随机字符。
更新:[ 我通过我的 html.tpl.php 文件 (print_r($css)) 检查了 $css 变量,发现我确实有一个幻影列表:
[http://mysite.gotpantheon.com/] => Array
(
[type] => external
[group] => 100
[every_page] => 1
[weight] => 999.009
[media] => all
[preprocess] => 1
[data] => http://mysite.gotpantheon.com/
[browsers] => Array
(
[IE] => 1
[!IE] => 1
)
)
我如何检查这个 css 元素被添加到哪里?奇怪的是,这个 css"file"是用绝对 url 列出的,而所有其他的都是相对 url(即 module/example/style.css)
]
这是我的 html 头中的两个幻象链接:
在我的主题 .info 文件中声明的最终 css 文件之后立即显示。 (注意它在“style”标签之外。)
<style>
...
...
@import url("http://my-site.gotpantheon.com/sites/all/themes/oak_intranet/css/oak_intranet.css?n5w7ml");
</style>
<link type="text/css" rel="stylesheet" href="?n5w7ml" media="all" />
在作为安装一部分的 IE 样式表之后随机出现。
<!--[if lte IE 8]>
<link type="text/css" rel="stylesheet" href="http://mysite.gotpantheon.com/profiles/openatrium/modules/panopoly/panopoly_core/css/panopoly-fonts-ie-open-sans-bold-italic.css?n5w7ml" media="all" />
<![endif]-->
<link type="text/css" rel="stylesheet" href="http://mysite.gotpantheon.com/" media="all" />
有一段时间,我被卡在出现的 ?n5w7ml 字符上,这里有一个很好的答案来解释为什么会发生这种情况:Weird characters at the end of src/href attributes in head tag
更多信息:
这是在 panopoly_core.module 中添加 IE 样式的地方。我想也许这里会有一些东西正在注册一个额外的 css 文件(空白或其他东西)并将其附加到基本 url。虽然没有看到它。
/**
* Implemenets hook_page_build().
*/
function panopoly_core_page_build(&$page) {
// This fixes a bug that causes @font-face declarations to break in IE6-8.
// @see http://www.smashingmagazine.com/2012/07/11/avoiding-faux-weights-styles-...
$path = drupal_get_path('module', 'panopoly_core');
drupal_add_css($path . '/css/panopoly-fonts-ie-open-sans.css', array('group' => CSS_THEME, 'every_page' => TRUE, 'browsers' => array('IE' => 'lte IE 8', '!IE' => FALSE), 'preprocess' => FALSE));
drupal_add_css($path . '/css/panopoly-fonts-ie-open-sans-bold.css', array('group' => CSS_THEME, 'every_page' => TRUE, 'browsers' => array('IE' => 'lte IE 8', '!IE' => FALSE), 'preprocess' => FALSE));
drupal_add_css($path . '/css/panopoly-fonts-ie-open-sans-italic.css', array('group' => CSS_THEME, 'every_page' => TRUE, 'browsers' => array('IE' => 'lte IE 8', '!IE' => FALSE), 'preprocess' => FALSE));
drupal_add_css($path . '/css/panopoly-fonts-ie-open-sans-bold-italic.css', array('group' => CSS_THEME, 'every_page' => TRUE, 'browsers' => array('IE' => 'lte IE 8', '!IE' => FALSE), 'preprocess' => FALSE));
}
更新:
因此,我注意到在我的 css 数组中,只有两个外部样式表,一个是我的幻像域样式表实例。我将我的网站带到我的本地主机并在所有核心文件中搜索术语“外部”。尽管列出了很多,但我很幸运,第一个是 colorizer.module。第 54 行有一个 drupal_add_css。我在那里的数组中添加了一个 'test' => 'test' 元素并重新加载了我的站点。我在 print($css) 数组中的幻像 css 文件现在有那个测试项。而且,它是唯一的。出于某种原因,着色器的 css 文件没有被添加,而是添加了一个空白?
[http://mysite.loc:8888/] => Array
(
[type] => external
[group] => 100
[every_page] => 1
[weight] => 999.008
[test] => test
[media] => all
[preprocess] => 1
[data] => http://mysite.loc:8888/
[browsers] => Array
(
[IE] => 1
[!IE] => 1
)
)
最佳答案
检查缓存,禁用缓存css文件
关于css - Drupal 正在向我的头脑中添加幻影样式表引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23771787/