


Popular version of JS code optimization skills (reduce js size)_javascript skills
After reading this article carefully, you will be able to optimize for most of the day. Most of the JS optimization methods cannot be separated from these three methods.
(The total size of the web page is 155.k, and JS accounts for 100.3K)
It’s time to optimize JS
There are already many articles about JS optimization, most of which are very technical, such as variables, strings, and types. I won’t introduce them. There is no need to introduce them. I don’t understand them either. It’s useless if you know them. Most webmasters are "using it". I just need to tell JS how to put it and delete it there.
Today’s websites are equipped with statistical codes, sharing tools, comment lists, related article plug-ins and other tools. To achieve powerful functions, JS files must be used. It is these JS plug-ins that enhance the functions of the website. , also affects the website speed.
The most commonly used JS optimization methods
Judging from the blog’s call to JS, the ones that currently have the greatest impact on speed are Wumi plug-ins (952ms) and Nafoneng Ads (434ms). If you really want to use it, you can keep it and optimize it appropriately according to the official textbook. Below, Lu Songsong introduces some of the most commonly used JS optimization methods.
Method 1: Put unimportant JS at the bottom of the page
This is the simplest and most effective optimization method. Put all unimportant JS at the bottom of the page above the body to achieve asynchronous loading, that is, wait for the web page to be loaded, and finally load these unimportant JS files. JS, so it will not affect the speed of the web page.
For example, the default effect of the util.js public file in the low-key and gorgeous templates is that when browsing the webpage, the special effect of "return to the top and write a comment" will appear on the webpage. Now wumii (Wumi plug-in JS) and jiathis (sharing tool JS) are integrated into the util.js file.
(The unimportant JS has been placed at the bottom of the page)
Of course, other websites also need to do this: put all unimportant JS at the bottom of the page.
Method 2: Merge JS files
Merge JS, which means reducing HTTP requests and making fewer requests to the server to speed up the process. Merging two originally independent JS requires some skills, but this is not a problem for us. Let us tell you the simplest method. :
No matter what, first paste the A file directly into the B file. After merging, delete the A file in the web page. If the web page runs normally, it is OK; if some special effects fail, then restore it and replace the C file. merge. There will always be two JS files that do not conflict.
For example, the Baidu Ad Manager on my blog has 6 ad slots. By default, 6 HTTP requests are required. Because it is a third-party JS, a request takes 234ms at the fastest, and 6 requests will take 2 seconds, that is to say, it will take an extra 2 seconds to open the web page because of this advertising manager.
(The second piece of JS turns 6 requests into 1)
After merging JS according to the official tutorial, the ad requests for 6 ad slots are merged into one request, which greatly reduces the number of js requests, effectively reduces the blocking of page rendering, and improves the ad loading speed.
Method 3: Lose weight for JS files
We won’t discuss the ternary operator, reducing object searches, or how to make JS concise. We will use the “JS Weight Loss Tool”. Usually such tools will compress hundreds of lines of code in a JS file into one line, making the size smaller. Recommended tools: http://javascriptcompressor.com/ or Software version (good fault tolerance effect)
Because of problems such as blank lines, sometimes using such tools will invalidate the JS function. The easiest way is to use Dreamweaver and put the compressed JS into DW. DW will automatically prompt you that there is an error. Just start a new line where the error occurred, or restore it.
Finally, let me give a netizen’s personal experience:
When your site grows slowly over time, you will find many problems, one of which is that it becomes more and more bloated, so the running speed will also slow down. Optimization, trying your best to optimize the site, has become very important.
These methods are easy to understand and I hope they are useful to everyone!

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

JavaScript's applications in the real world include server-side programming, mobile application development and Internet of Things control: 1. Server-side programming is realized through Node.js, suitable for high concurrent request processing. 2. Mobile application development is carried out through ReactNative and supports cross-platform deployment. 3. Used for IoT device control through Johnny-Five library, suitable for hardware interaction.

I built a functional multi-tenant SaaS application (an EdTech app) with your everyday tech tool and you can do the same. First, what’s a multi-tenant SaaS application? Multi-tenant SaaS applications let you serve multiple customers from a sing

This article demonstrates frontend integration with a backend secured by Permit, building a functional EdTech SaaS application using Next.js. The frontend fetches user permissions to control UI visibility and ensures API requests adhere to role-base

JavaScript is the core language of modern web development and is widely used for its diversity and flexibility. 1) Front-end development: build dynamic web pages and single-page applications through DOM operations and modern frameworks (such as React, Vue.js, Angular). 2) Server-side development: Node.js uses a non-blocking I/O model to handle high concurrency and real-time applications. 3) Mobile and desktop application development: cross-platform development is realized through ReactNative and Electron to improve development efficiency.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Zend Studio 13.0.1
Powerful PHP integrated development environment

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download
The most popular open source editor