前端性能优化

前端性能优化

Jerome Xiong
Jerome Xiong

前端性能优化是提升用户体验的关键环节。本文汇集了Vue首屏加载优化、图片渐进式加载、SSR服务端渲染以及Gzip压缩等多个方向的实用资源与配置示例,供开发者参考使用。

Vue

图片

plugins

简单的改造SEO(预渲染

ERROR: Failed to download Chromium

vue.config.js

1// 推荐使用cnpm安装prerender
2const PrerenderSpaPlugin = require("prerender-spa-plugin");
3const CompressionPlugin = require("compression-webpack-plugin");
4module.exports = {
5  publicPath: "/",
6  outputDir: "server/dist",
7  assetsDir: "static",
8  productionSourceMap: false,
9  lintOnSave: false,
10  configureWebpack: config => {
11    // seo 预渲染
12    const prerender = new PrerenderSpaPlugin(config.output.path, ["/", "/login"]);
13    // 会渲染login页面
14    const gzip = new CompressionPlugin({
15      test: /\.js$|\.html$|\.css/, //匹配文件名
16      threshold: 10240, //对超过10k的数据进行压缩
17      deleteOriginalAssets: false
18    });
19    if (process.env.NODE_ENV === "production") {
20      config.mode = "production";
21      return {
22        plugins: [prerender, gzip]
23      };
24    }
25  }
26};
  • 标题: 前端性能优化
  • 作者: Jerome Xiong
  • 创建于: 2020-03-15 18:00
  • 链接: https://jeromexiong.github.io/2020/03/15/Web-前端/前端性能优化/
  • 版权声明:本文章采用 CC BY-NC-SA 4.0 进行许可。
评论