node.js - 将express与ejs一起使用时如何从磁盘或内存中加载资源
问题描述
我正在使用Firebase托管通过Express和Ejs提供我的网站内容。
每次用户请求模板页面时,如何从磁盘或内存加载资源(CSS、Javascript、图像、字体)而不是请求资源?
以其他格式“如何将状态代码从 304 更改为 200(从磁盘缓存)? ”。
索引.ejs
<!DOCTYPE html>
<html>
<head>
<title><%= PageTitle %></title>
<link rel='stylesheet' href='assets/css/reset.css'>
<link rel='stylesheet' href='assets/css/icons.css'>
<link rel='stylesheet' href='assets/css/plyr.css'>
<link rel='stylesheet' href='assets/css/styles.css'>
</head>
<body>
<h1><%= PageTitle %></h1>
<script src='assets/js/jquery.min.js'/>
<script src='assets/js/plyr.js'/>
<script src='assets/js/scripts.js'/>
</body>
</html>
index.js
const express = require('express');
const ejs = require('ejs');
const app = express();
app.set('view engine', 'ejs');
app.use(express.static(__dirname + '/public'));
app.get('/', (req, res) => {
res.render('index', { PageTitle: "Homepage" });
});
exports.app = functions.https.onRequest(app);
firebase.json
{
"hosting": {
"public": "functions/views",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"function": "app"
}
]
}
}
解决方案
推荐阅读
- javascript - 如何使用 NavWalker 和 bootstrap.min.css 在 WordPress 中创建 Bootstrap 导航栏
- mysql - 通过 findAll 函数将选择日期序列化到列之间
- python - 数据框 - InvalidIndexError
- javascript - 我试图推入数组的调度正在调用它
- swift - 在调用 SwiftUi 中获取错误额外参数
- matlab - 地图投影需要多长时间?
- javascript - 如何更改引导导航的滚动文本颜色
- python - 在 Odoo 看板视图中显示和隐藏按钮
- directory - 如何使 Trace32 路径适用于所有其他用户?
- android - 删除用于接收 android.intent.action.SEND 的“选择对话”对话框