There is a page, because the js file is very large, so the first time to load this page is very slow, the web server is nginx, wants the page to load faster

there is a page. Because the js file is very large, it is slow to load this page for the first time. The web server is nginx,

.

I hope the page can load faster. How to configure it in nginx to make this page load faster

or how to modify the page to make it load fast


  1. the first step you can do right away is to put the js reference at the end of the body to speed up the presentation of the entire page.
  2. if the JS file is very large, it will be loaded into several files according to functionality and dependencies.
  3. if the content in that js file is not necessary for every page, it is recommended to load it on demand. You can use requirejs .

provides several quick solutions:

  1. compress the code as much as possible without generating map
  2. nginx enables gzip, to improve a lot
  3. upload to cdn, such as Qiniuyun
  4. optimize code structure to load on demand
  5. split the common code and the business code. The common code can not be updated later. Use the http cache

many of the solutions mentioned above can be solved using webpack, gulp, and so on, depending on what your project is like.


webpack enable compression, as shown in figure

  1. npm install-- save-dev compression-webpack-plugin
  2. productionGzip: false, false changed to true


can you ask a bigger question?

it's like telling the doctor that you're not feeling well and asking the doctor to give you a prescription.

Let me tell you a little bit about the way of thinking when you encounter this kind of problem.

first of all, your problem should be that loads this page very slowly for the first time .

so what is the reason for the slow loading speed?
to know why the loading speed is slow, you need to know how browsers render web pages.

Let me briefly say that the browser is generally divided into two processes from the beginning to the rendering:

  1. request HTML
  2. parsing HTML, if it encounters CSS or JS (regardless of asynchronous scripts), it will wait for it to download and parse

so consider optimization in terms of download speed and parsing speed.

to improve download speed, it is easy to think of dividing a large file into multiple small files. But this optimization is not always successful, and it is not difficult to understand why it can improve performance.

improving parsing speed is also easy to think of not writing complex JS operations, or putting complex operations into RAF or RIC. But it doesn't matter.
what matters is that you know how it works and how to make choices in different situations

For more information, please see my article on front-end performance optimization. Address: https://github.com/azl3979858.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b2c0ae-2baec.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b2c0ae-2baec.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?