Home Web Front-end JS Tutorial Comprehensive optimization strategy for vue projects

Comprehensive optimization strategy for vue projects

May 23, 2018 pm 03:03 PM
optimization comprehensive Strategy

This time I will bring you a comprehensive optimization strategy for the vue project. What are the precautions for the comprehensive optimization of the vue project. The following is a practical case, let's take a look.

PicturesOptimization

1. Picture size optimization, some pictures use WebP (webp compatibility needs to be considered)

  1. Online generation, such as Zhitu and Youpaiyun

  2. gulp generation, gulp-webp or gulp-imageisux

  3. canvas Generate

2. Reduce image requests and use sprite images

  1. to generate online: sprites Generator, Tencent’s gopng, spriteme

  2. Code generation: gulp.spritesmith or sass compass

##PagePerformance optimization

Lazy loading of images or components

Use vue-lazyload component or some other components

vue-lazyload address:

https://www.npmjs.com/package/vue -lazyload

Picture lazy loading: v-lazy or use v-lazy-container to contain a picture group

// 引入一张图片 
<img v-lazy="//domain.com/img1.jpg"> 
// 引入一组图片
<p v-lazy-container="{ selector: &#39;img&#39;, error: &#39;xxx.jpg&#39;, loading: &#39;xxx.jpg&#39; }">
 <img src="//domain.com/img1.jpg">
 <img src="//domain.com/img2.jpg">
 <img src="//domain.com/img3.jpg"> 
</p>
Copy after login
Component lazy loading

Vue.use(VueLazyload, {
 lazyComponent: true
});
<lazy-component>
 <img class="mini-cover" :src="img.src" width="100%" height="400">
</lazy-component>
Copy after login

Picture preloading

Quickly display pictures

Usage scenario: In a component that views pictures, when constantly flipping through the pictures on the next page, the picture will appear after getting the data from the server and then displaying the picture. In the case of slow loading, you can preload the image when displaying new data. After the image is loaded, fill the image into the corresponding position

Three-party plug-in lazy loading (loading on demand)

JS files are generally loaded synchronously, and placing them in the page will block the loading of the main JS files.

Usage scenarios: When some projects must introduce files such as jquery, introducing these files inside the component will block page rendering to a certain extent, so it is dynamically loaded through specific

events (click or pop-up window) JS files such as jquery can quickly display the main page.

Asynchronous loading of pages, how to prevent components from overlapping

When multiple vue components are loaded and the components are rendered through server-side data, multiple components will first overlap and then separate. Situation

Three options

  • #When the section displayed on the page is fixed and the height of the content is not easy to change, it can be set outside the component in advance A fixed height that displays like adding content to a frame. When the page content is not fixed, in order to reduce the problem of overlapping components during asynchronous loading, you can set other components to be displayed on the first screen when the data of a certain component is loaded, and displayed through v-show.

  • When the page is fixed as a whole, you can add a skeleton to the page to prevent the page from flickering. For specific implementation, please refer to http://www.jb51.net/article/130505.htm

  • Server-side rendering page. For some pages with fixed data and few changes, you can consider passing Server-side rendering will display the page in a short time, providing a better user experience.

Reduce the size of imported external files

When the project introduces some ElementUI content, configure the .babelrc file by introducing babel-plugin-component, so that Partial components can be introduced to reduce the size of the component.

Routing lazy loading

But when using vue-router, webpack will package all components in a js file, which will cause the file to be very large, thus It will affect the loading of the homepage. The best way is to package other routes into different js files, and then load the corresponding js files when switching routes.

resolve => require([URL], resolve), 支持性好
() => system.import(URL) , webpack2官网上已经声明将逐渐废除, 不推荐使用
() => import(URL), webpack2官网推荐使用, 属于es7范畴, 需要配合babel的syntax-dynamic-import插件使用
Copy after login

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

How to use vue to register components

How to use Vue three-layer nested routing

The above is the detailed content of Comprehensive optimization strategy for vue projects. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Collapse Star Dome Railway Underworld Relic Set Matching Guide Collapse Star Dome Railway Underworld Relic Set Matching Guide Mar 27, 2024 pm 04:10 PM

How to choose the underworld relics of the Collapsed Star Dome Railway? The new five-star character Huang Quan has officially debuted, and many players have already drawn her. This character is positioned as the main C output. Below, the editor brings the Huang Quan relic set and entry recommendations, hoping to be helpful to all of you. 1. For the suit, it is recommended to choose the four-piece set [Pioneer of Backwater Diving], and for the plane jewelry, it is recommended to choose [Izumo Xianshi and Gaotian Divine Kingdom] or [Stalled Sarsotu]. 2. The main entries are selected as follows: torso critical hit rate/critical hit damage, foot attack/speed, plane ball lightning damage/attack, and link rope attack power. The selection of adverbs is: give priority to double violence, just meet the threshold or be as high as possible, and then stack speed and attack power. 3. Note: ① A four-piece outer ring set is the best for stagnant water. The thunder set is suitable for stagnant water when wearing a thunder ball and speed shoes.

Achievement Guide for Collapse Star Dome Railway Tianzhan Muzan Achievement Guide for Collapse Star Dome Railway Tianzhan Muzan Mar 28, 2024 am 08:26 AM

The Collapse Star Dome Railway Tian Zhan Wu Zhan is an exclusive achievement for Huang Quan. Many players don’t know how to obtain the Tian Zhan Wu Zhan achievement. It is actually very simple. First, use Fu Xuan to attract the monsters on both sides together, and then teleport back to the previous teleport. Click and then use Huangquan to fight. Let’s take a look at this guide to obtain the Honkai Star Dome Railway Tianzhan Muzan achievement for details. Honkai Star Dome Railway Guide Complete Guide to Honkai Star Dome Railway Tianzhan Muzan Achievement Guide 1. Teleport to the location in the picture below. 2. First use Fu Xuan to attract the monsters on both sides together. 3. Then teleport back to the teleport point just now. If you have no achievement points, you can make up for them. 4. After that, you can get the achievement by using Huang Quan to cut five times in a row.

Collapse Star Dome Railway Double Indemnity Mission Guide Process Collapse Star Dome Railway Double Indemnity Mission Guide Process Mar 28, 2024 pm 02:20 PM

How to do double compensation on the Honkai Star Dome Railway? Double compensation is part of the main mission [Cat among Pigeons]. In this mission, you can obtain the hidden achievement of "Stealing the Blind Bet". Below, the editor will provide a detailed explanation of the double compensation mission of the Collapsed Star Dome Railway, hoping it will be helpful to the players. help. 1. Come to the new map [Chaolu Mansion] and go in through the front door. 2. After entering through the door in the picture above, rotate the four statues in the picture below correctly and the correct hidden door will appear. Then continue the task and follow the tracking task first. Go to the 1st and 2nd mission points to talk, and then switch to the 3rd position, you can consume consumables first to fill up Sand Gold's finishing move with energy before entering the battle. After entering the battle, just release Sand Gold's finishing move first. If you can get 7 [Blind Bet] points at one time, you can get the hidden achievement "Stealing the Blind Bet"; note

C++ program optimization: time complexity reduction techniques C++ program optimization: time complexity reduction techniques Jun 01, 2024 am 11:19 AM

Time complexity measures the execution time of an algorithm relative to the size of the input. Tips for reducing the time complexity of C++ programs include: choosing appropriate containers (such as vector, list) to optimize data storage and management. Utilize efficient algorithms such as quick sort to reduce computation time. Eliminate multiple operations to reduce double counting. Use conditional branches to avoid unnecessary calculations. Optimize linear search by using faster algorithms such as binary search.

Guide to the Devil in Velvet on the Collapsed Star Dome Railway Guide to the Devil in Velvet on the Collapsed Star Dome Railway Mar 28, 2024 am 11:26 AM

The Devil in Velvet is a brand new mission launched in this version. Many players are very curious about how to complete this mission. Today, the editor has brought you a picture and text mission guide for this mission. Players can pass This guide is used to solve the puzzles in the mission and complete the mission faster. The detailed content can be found in this graphic mission guide of The Devil in Velvet. Let’s take a look together. Guide to the Demon in the Velvet of the Collapsed Star Dome Railway 1. First, the player needs to reach level 34 and complete the prerequisite task [Who killed...], then you can automatically accept this task. 2. Go to Pinoconi’s Platinum Suite and talk to Sand Gold and Black Swan. 3. Then follow the movement of the black swan and go to the golden moment in the dream. 4. Come to the clock

Dragon's Dogma 2 Disaster Arrival Guide Dragon's Dogma 2 Disaster Arrival Guide Mar 28, 2024 pm 03:43 PM

The Arrival of Disaster is a side quest in the game. Many players don’t know how to complete the Arrival of Disaster. It is actually very simple. Go to Mevi Village to trigger the Arrival of Disaster quest, then talk to Ulika, and then go to Mevi Village to find it in two days. Ulika discovered that Ulika was missing. Let’s take a look at this Dragon’s Dogma 2 Disaster Arrival graphic guide for details. Dragon's Creed 2 Guide Dragon's Creed 2 Disaster Arrives Guide 1. Go to Meiwei Village and trigger the Disaster Arrive mission. 2. Talk to Ulika. 3. Go back to Meiwei Village to look for Ulika in two days and find that Ulika is missing. 4. Go to Harvard Village. 5. Complete two challenges to eliminate the lizardmen. 6. After talking to the villagers, you will find that Ulika is in the village. Then just ask Mevi to deliver the task.

Collapse Star Dome Railway Shura Xueji Achievement Guide Collapse Star Dome Railway Shura Xueji Achievement Guide Mar 28, 2024 am 08:06 AM

Collapse Star Dome Railway Shura Snow Princess is an exclusive achievement of Huang Quan. Many players don’t know how to obtain the Shura Snow Princess achievement. It is actually very simple. First, give the opponent a negative status, and then use Huang Quan’s ultimate move to kill it. The specific content is as follows: Get up and take a look at this guide to obtain the achievement of Shura Xueji on the Collapsed Star Dome Railway. Honkai Star Dome Railway Guide Complete Guide to Shura Xueji Achievement of Honkai Star Dome Railway 1. Enter the copy below. 2. The lineup is Huang Quan, Fu Xuan, Hanabi, and Pella. 3. First put a negative state on the opponent, and then charge Huangquan's ultimate move. Note that no monster on the opponent can die. Huangquan does not do enough damage to control the blood. 4. Finally, Huang Quan kills all the mobs to obtain the achievement.

What are some ways to resolve inefficiencies in PHP functions? What are some ways to resolve inefficiencies in PHP functions? May 02, 2024 pm 01:48 PM

Five ways to optimize PHP function efficiency: avoid unnecessary copying of variables. Use references to avoid variable copying. Avoid repeated function calls. Inline simple functions. Optimizing loops using arrays.

See all articles