使用express-simple-cdn可以提高性能,但在控制台中会收到404-not-found错误

时间:2019-09-24 12:04:35

标签: express http-status-code-404 cdn

我通过在我的Linux操作系统的/ etc / hosts中映射本地ip域,在我的角度应用程序中实现了express-simple-cdn。使用铬灯塔的性能从50提高到80。但是,我在浏览器上点击应用程序URL时得到的-

my project-error

我的代码是-

app.js成角度(当我通过app.js文件运行我的角度应用)

var CDN = "http://myproject.test"

app.locals.CDN = function(path, type, classes, alt) {
    if(type == 'js') {
        return "<script src='"+CDN+path+"' type='text/javascript'></script>";
    } else if (type == 'css') {
        return "<link rel='stylesheet' type='text/css' href='"+CDN+path+"'/>";
    } else if (type == 'img') {
        return "<img class='"+classes+"' src='"+CDN+path+"' alt='"+alt+"' />";
    } else {
        return "";
    }
};

module.exports = app;

index.html

 <img class="img-responsive" style = "visibility:hidden" src="http://myproject.test/../../assets/images/insta.BIZ.banner.d.jpg.png" alt="my picture" />

即使我将路径更改为-

<img class="img-responsive" style = "visibility:hidden" src="http://myproject.test/assets/images/insta.BIZ.banner.d.jpg.png" alt="my picture" />

我仍然遇到相同的错误。也是因为Lighthouse中的错误导致我的阅读错误吗?

1 个答案:

答案 0 :(得分:0)

我需要用单引号将html中的值输入--

<img class="img-responsive" style = "visibility:hidden" src="'http://myproject.test/assets/images/insta.BIZ.banner.d.jpg.png'" alt="my picture" />