White during optimization
-
Route lazy loading
{ path: '/login'.component: () = > import('@aicc/components/login/index')}Copy the code
-
Use v-if instead of v-show
The advantage is that you can reduce the amount of DOM rendered in the first screen (except for elements that frequently change explicit and implicit, for which you should use V-show).
-
Components that do not display directly do lazy loading
A common scenario is that components in the el-Tabs component that are rendered from the second TAB can be loaded lazily to reduce the amount of code that needs to be loaded to complete the first screen rendering based on this path
Like in the VUE project
import pageComponent from './pageComponent' export default { name: 'Recharge'.components: { pageComponent, }, ... Copy the code
to
export default { name: 'Recharge'.components: { pageComponent: () = > import('./pageComponent'),},...Copy the code
-
Use the resolutions unified dependent version
Assume that the main project depends on package [email protected], and the main project depends on package B depends on [email protected]. In this case, YARN installs two versions of A in node_modules root path and node_modules/B/node_modules respectively, and packages them into the final bundle. At this point, resolutions can be used to force the unified version of A in package.json
"resolutions": { "a": 1.1.1 "" } Copy the code
-
Component libraries are loaded on demand
This includes third-party component libraries used by the project, in-house component libraries, and components in the project components directory, all of which can be implemented using the babel-plugin-import plugin, babel.config.js as follows:
const babelPluginImportForComponents = [ 'import', { libraryName: '@/components'.libraryDirectory: ' '.camel2DashComponentName: false.customName: name= > { return `@/components/${name}`}}]module.exports = { ... 'plugins': [ ... babelPluginImportForComponents ] } Copy the code
-
Resource preloading
For example, a CSS package that uses Element will load the font via @font-face. This means that the font will wait for the CSS to load and start parsing. This way, we can preload the font without waiting for the CSS
This typically deals with font resources: or any other resource that has to load the first screen while waiting for other resources to load first
-
defer
For js resources that have little impact on rendering, defer can be added to script so that they don’t block rendering or load, such as iconFont’s color font JS file
-
CDN
Part of static resources can be put on the CDN, the advantage is that the request for these resources will not bring the cookie of this website, reduce traffic. Some excellent CDN will also accelerate the loading speed of resources, such as Qiniu and Ali
-
Reduce CSS loading
The reason is that loading CSS blocks dom rendering because browsers build two trees to render the DOM: the DOM tree and the CSS rule tree before rendering. Load only the CSS required for the first screen, preferably with
-
gzip
Pack it into a Gzip package, without the server to do compression
-
Static file cache
Currently, front-end resources are classified using hash versions. If the hash remains the same, you can always cache the resources and set a cache policy on the server
-
Server render/prerender
This is the ultimate killer, because accessing the URL directly requests a piece of HTML and styles that can be rendered and the rest of the resource can be loaded without blocking. It can be said that using this scheme reduces a lot of optimization effort
The first screen to optimize
In fact, the above scheme is also the first screen optimization scheme, here is to emphasize the white screen after the end of the processing
-
Skeleton screen /loading dynamic effect
If some content on the first screen needs to be rendered after requesting data through the interface, the skeleton screen or loading effect can be rendered first to make the user feel that the page is being loaded
-
Back-end data layer caching
Some frequently queried data can be set cache, such as taobao home page commodity list
-
Picture lazy loading (can cooperate with skeleton screen scheme)
-
Image compression
tinyPng