node.js - Google 网络字体在 Express 中不起作用

标签 node.js express google-webfonts

我无法让 Google 网络字体在 express 3.0 中工作。

以标准方式加载字体似乎不起作用:

link(href='http://fonts.googleapis.com/css?family=Crete+Round')

但是以这些方式之一加载字体工作正常:

    script(type="text/javascript")
        WebFontConfig = {google: { families: [ 'Crete+Round::latin' ] }};
        (function() {
            var wf = document.createElement('script');
            wf.src = ('https:' == document.location.protocol ? 'https' : 'http') + '://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
            wf.type = 'text/javascript';
            wf.async = 'true';
            var s = document.getElementsByTagName('script')[0];
            s.parentNode.insertBefore(wf, s);
        })();

    style
        @import url(http://fonts.googleapis.com/css?family=Crete+Round);

最佳答案

我在不包括 CSS 的 Express 3.0.0rc2 上遇到过类似的问题。我不确定这是 Jade 还是 Express 的问题,但是当我添加一个有效的 style.css 时,它工作得很好,就像这样:

link(rel='stylesheet', href='/stylesheets/style.css')

但是,如果我删除该行并插入,比如说 Twitter Bootstrap css 文件,我会得到奇怪的 HTML 输出。

link(rel='stylesheet', href='/bootstrap/css/bootstrap.min.css')

它只有在我有这样的东西时才有效:

link(rel='stylesheet', href='/bootstrap/css/bootstrap.min.css')
link(rel='stylesheet', href='/bootstrap/css/bootstrap-responsive.min.css')
link(rel='stylesheet', href='/stylesheets/style.css')

为什么?我不知道。 :-) 我认为这与解析和 HTML 输出有关。

关于node.js - Google 网络字体在 Express 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11962389/

相关文章:

node.js - 将更改后的文件名传递给 nodemon 中的命令

node.js - 为什么 Node.js/Express 不接受来自本地主机的连接?

arrays - Array .push 在每个循环内返回用相同对象填充的数组

javascript - 1 :m (using belongsTo and hasMany). 的问题结果不反射(reflect)提议的模型

node.js - 尝试 POST 请求时 Node js 出错

mysql - SequelizeConnectionRefusedError : connect ECONNREFUSED 127. 0.0.1:3306

css - 什么是网络字体,我可以依赖它们吗

css - 谷歌字体——谷歌浏览器中的部分渲染

javascript - Webfont 性能 - webfontloader 与预加载

node.js - 如何在 express js 中手动触发路由处理程序?