0

clipboard.png

如图,这是一个NUXT项目,使用 nuxt generate 生成,首次访问时把所有页面的js给加载了

查看js的时候发现了这样一段代码,把所有的js一次性加载完了

d.e = function(e) {
        var c = []
          , t = f[e];
        if (0 !== t)
            if (t)
                c.push(t[2]);
            else {
                var r = new Promise(function(c, r) {
                    t = f[e] = [c, r]
                }
                );
                c.push(t[2] = r);
                var n, script = document.createElement("script");
                script.charset = "utf-8",
                script.timeout = 120,
                d.nc && script.setAttribute("nonce", d.nc),
                script.src = function(e) {
                    return d.p + "" + {
                        0: "37c3f3c0896d929e270e",
                        1: "d9fe981ffa4eb648a888",
                        4: "dedf85295c69a224c08a",
                        5: "db74892bed63b8214e2c",
                        6: "66f3600ec844c9ca8d94",
                        7: "49afe98d6ce0b0091e2e",
                        8: "6f0eef6f8de1ba3fc450",
                        9: "5e0281c666b46ec44648",
                        10: "43db1aef2a05b6381123",
                        11: "e0e4cbd248af939bf293",
                        12: "62f43f50253f83bc520d",
                        13: "06632b9b9ab23136110c",
                        14: "7d297dc29b1e27701560",
                        15: "5589468d3f242b1b65c1",
                        16: "292dc9115138513e3c56",
                        17: "09d600c687f4e7838dda",
                        18: "63dc0135b1201e74434c",
                        19: "9dea1ec1a061ced19075",
                        20: "3f7d1c978fecf92d2c90",
                        21: "81278399437efbce90fd",
                        22: "e234eb6a8d8e5a6ba393",
                        23: "7a06cadc851fa5f6e46f",
                        24: "90bae1db178204e2ad0a",
                        25: "6daf5fe5949052093bdc",
                        26: "ea697339f7155e811cd0",
                        27: "1eba153312544d77d72b",
                        28: "3ad25f84372e9f091a0b",
                        29: "29011408009566ab3630",
                        30: "8ee99c977f41f1e0ce61",
                        31: "b75367d751834f185e6a",
                        32: "4581b8e7a1f05c469c77",
                        33: "c4228098a2d4492210b1",
                        34: "337a840ce215b34d0a56",
                        35: "e8390b9d81c893acfc15",
                        36: "e79827b4dd77b1cd323d",
                        37: "03020607c2c5a42c968f",
                        38: "8e51837ff4b6b7bba571",
                        39: "da230cd3d81bef66fc59",
                        40: "ec6e5ff095cd1f4f8642",
                        41: "534ece81e7e75a4fbc5c",
                        42: "3b4e9f6979cd9cdf72dc",
                        43: "1d833710443ab40f04f4",
                        44: "8e2962137012f59e6b36",
                        45: "a007171590695adbb1c8",
                        46: "d3c6fb02063acfc56004",
                        47: "b4b80e9b7e2fdf8cb29b",
                        48: "de50e2837843c1ce351e",
                        49: "77eb8ea781823d9c4d72",
                        50: "aea8b174250df6e5d36c",
                        53: "c281b141f27eb8900b3b",
                        54: "aa8491cec8bfd7964a44"
                    }[e] + ".js"
                }(e),
                n = function(c) {
                    script.onerror = script.onload = null,
                    clearTimeout(o);
                    var t = f[e];
                    if (0 !== t) {
                        if (t) {
                            var r = c && ("load" === c.type ? "missing" : c.type)
                              , n = c && c.target && c.target.src
                              , d = new Error("Loading chunk " + e + " failed.\n(" + r + ": " + n + ")");
                            d.type = r,
                            d.request = n,
                            t[1](d)
                        }
                        f[e] = void 0
                    }
                }
                ;
                var o = setTimeout(function() {
                    n({
                        type: "timeout",
                        target: script
                    })
                }, 12e4);
                script.onerror = script.onload = n,
                document.head.appendChild(script)
            }
        return Promise.all(c)
    }

导致首屏的加载时间非常的长,按理说应该只是预加载所有的js请求,而不是加载js的内容,应该如何处理,文档中也没有找到相关的配置

在GitHub上看到一个类似的issues https://github.com/nuxt/nuxt.js/issues/905 但是已经关闭很长时间了

2019-03-14 提问
2 个回答
0

请问问题已经解决了吗?我司现在遇到一样的情况,望解答,谢谢~

0

https://zh.nuxtjs.org/api/con...
我用了这个解决了,貌似中文文档是最近才更新上去的,上次被坑了

撰写答案

推广链接