[英]Loading a custom CSS Handler for Node.JS
I have a basic Node.JS server setup as I'm doing a new project for work. 我有一个基本的Node.JS服务器设置,因为我正在做一个新的项目。 I've written and optimizer function that strips unnecessary things like tabs, newlines and comments from HTML, JavaScript and CSS.
我已经编写了优化程序功能,该功能可以从HTML,JavaScript和CSS中去除不必要的内容,例如标签,换行符和注释。
For some odd reason when I added my <link type="text/css" href="/css/bootstrap.mins.css">
to my head it's not loading or showing up in the Google Network tab. 由于某些奇怪的原因,当我将
<link type="text/css" href="/css/bootstrap.mins.css">
到我的头部时,它没有加载或显示在Google联网标签中。
The main HTML is loading just not the CSS. 主要的HTML加载不是CSS。
Server: 服务器:
app.get("/css/:file",function(req,res){
logger.log("CSS File");
res.writeHead(200, {"Content-Type": "text/css"});
res.write(fs.readFileSync(appRoot + "/css/" + req.params.file,"utf8").optimize());
res.end();
});
There is no nested CSS files, all in one directory. 没有嵌套的CSS文件,都位于一个目录中。 This, in theory, should work but it isn't.
从理论上讲,这应该起作用,但事实并非如此。 It loads and is processed when I go to the direct URL.
当我转到直接URL时,它将加载并处理。 Just not from the LINK .
只是不是来自LINK 。
Loading the HTML Page: 加载HTML页面:
Loading the CSS Directly; 直接加载CSS; It does preprocess:
它会进行预处理:
Okay, after further study I found that my code above did work. 好的,在进一步研究之后,我发现上面的代码确实有效。 I had 1 slight failure though.
我虽然有1次轻微失败。 I missed the
rel
tag in the actual link. 我错过了实际链接中的
rel
标签。 The CSS loads fine and optimized after this. 此后,CSS会加载并优化。
<head>
<title>In House Tool</title>
<link rel="stylesheet" type="text/css" href="/css/bootstrap.min.css">
</head>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.