bundle.js加载速度非常慢

时间:2019-07-02 12:25:39

标签: node.js express

我正在使用ec2(nodejs + express + webpack)-cloudflare设置,我的捆绑包大小仅为100kb。

但是问题是100kb捆绑包花费的时间太长(25〜30秒)

我认为这是我的express或nodejs设置中的一个问题,因为index.html [1kb]也需要700毫秒,而favicon [2kb]则需要1.91s加载。

我想知道这是因为ec2 freetier速度慢还是我的设置使其保持如此缓慢。

我用

1个用于https连接的cloudflare ssl

2个iptables从80路由到3000(我的节点环境)

3个具有这样的主页的快递服务器


const app = express();
const port = process.env.p || 3000;

app.get('/', function (request, response){
    response.sendFile(path.resolve('public', 'index.html'), 'utf8');

});
app.use('/css', express.static('css'));
app.use('/static', express.static('static'));
app.use(express.static('public'));
app.use(bodyParser.urlencoded({extended: true }));
app.use(bodyParser.json());

app.post('/signup', (req, res) =>{
    signup(req.body, res);
});
app.post('/login', (req, res) =>{
    login(req.body, res);
});
app.get('/userlist', (req, res)=>{
    ulist(req.query, res);
});
app.get('/atoc', (req, res)=>{
    console.log(req.query);
    atocf(req.query, res);
});
app.get('/data/allshops', (req, res)=>{
    allshops(res);
});

app.get('/manager/checkurl', (req,res)=>{
    checkurl(req.query, res);
});
app.post('/manager/upload', upload.single('file'),(req,res)=>{
    s3u(req.file,req.body, res);
})
app.post('/manager/addshop', (req,res)=>{
    addshop(req.body, res);
});
app.post('/manager/editshop', (req,res)=>{
    editshop(req.body, res);
});
app.post('/manager/shop', (req,res)=>{
    mshopdata(req.body, res);
});
app.post('/manager/shops', (req,res)=>{
    myshops(req.body, res);
});
app.post('/manager/pub', (req,res)=>{
    msetpublic(req.body, res);
});
app.post('/manager/rm', (req,res)=>{
    msetrm(req.body, res);
});
app.post('/data/shop', (req,res)=>{
    if(req.body._url==undefined||req.body._url==''){
        res.send("{'ic_error':'NO_URL'}");
    }
    else
        shopdata(req.body, res);
});

app.get('*', function (request, response){

    const paths = request.path.split('/');
    if(nofollow.includes(paths[1])){
        response.sendFile(path.resolve('public', 'index.html'), 'utf8');
        return;
    }
    if(keypaths.includes(paths[1])){
        response.sendFile(path.resolve('public', paths[1]+'.html'),'utf8');
        return;
    }
    //shopmetadata({_url: decodeURIComponent(paths[1])}, response);
    sendpage({_url: decodeURIComponent(paths[1])},response)
});


const server = app.listen(port, () => {
    console.log('Express listening on port', port);
});

我正在做错什么,以至于如此缓慢地降低了流量?

提前谢谢!

0 个答案:

没有答案