节点,针对特定文件types的不同caching规则

我正在为我的应用程序禁用caching,如下所示:

app.use(function noCache(req, res, next) { res.header('Cache-Control', 'no-cache, no-store, must-revalidate'); res.header('Pragma', 'no-cache'); res.header('Expires', 0); next(); }); 

使用IE时,通过HTTPS使用这个问题有一个问题: https : //connect.microsoft.com/IE/feedbackdetail/view/992569/font-face-not-working-with-internet-explorer-and-http-header-语用无caching

如何更改上面的代码,使其不适用于字体types文件? 我认为这将解决我的问题。

谢谢

您可以检查req.path ,针对Web字体(ttf,woff,eot等)的扩展名,并在这种情况下跳过发回这些标头:

 const WEBFONT_EXTENSIONS = /\.(?:eot|ttf|woff|svg)$/i; app.use(function noCache(req, res, next) { if (! WEBFONT_EXTENSIONS.test(req.path)) { res.header('Cache-Control', 'no-cache, no-store, must-revalidate'); res.header('Pragma', 'no-cache'); res.header('Expires', 0); } next(); });