Web loading speed optimization

Posted by nano on Mon, 15 Jun 2020 09:28:52 +0200

introduction

Due to the recent work requirements, the user's loading speed needs to be greatly optimized.
Next, I will make a summary from the aspect of network request optimization. 😀

Some pictures are Sprite

Sprite map is also called CSS sprite. It is a kind of CSS image synthesis technology, which can reduce network requests by making multiple images one.


As the icon of station b:
https://s1.hdslb.com/bfs/stat...

Some pictures are svg

SVG is a language that uses XML to describe two-dimensional graphics and drawing programs.


Compared with JPEG and GIF images, SVG is smaller, more compressible and faster to load. And SVG is scalable, and the image can be printed with high quality at any resolution.


As shown in the loading Icon:

<?xml version="1.0" encoding="utf-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="margin: auto; background: rgb(255, 255, 255); display: block; shape-rendering: auto;" width="200px" height="200px" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid">
<g transform="rotate(0 50 50)">
  <rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#fe718d">
    <animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="-0.9166666666666666s" repeatCount="indefinite"></animate>
  </rect>
</g><g transform="rotate(30 50 50)">
  <rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#fe718d">
    <animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="-0.8333333333333334s" repeatCount="indefinite"></animate>
  </rect>
</g><g transform="rotate(60 50 50)">
  <rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#fe718d">
    <animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="-0.75s" repeatCount="indefinite"></animate>
  </rect>
</g><g transform="rotate(90 50 50)">
  <rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#fe718d">
    <animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="-0.6666666666666666s" repeatCount="indefinite"></animate>
  </rect>
</g><g transform="rotate(120 50 50)">
  <rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#fe718d">
    <animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="-0.5833333333333334s" repeatCount="indefinite"></animate>
  </rect>
</g><g transform="rotate(150 50 50)">
  <rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#fe718d">
    <animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="-0.5s" repeatCount="indefinite"></animate>
  </rect>
</g><g transform="rotate(180 50 50)">
  <rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#fe718d">
    <animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="-0.4166666666666667s" repeatCount="indefinite"></animate>
  </rect>
</g><g transform="rotate(210 50 50)">
  <rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#fe718d">
    <animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="-0.3333333333333333s" repeatCount="indefinite"></animate>
  </rect>
</g><g transform="rotate(240 50 50)">
  <rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#fe718d">
    <animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="-0.25s" repeatCount="indefinite"></animate>
  </rect>
</g><g transform="rotate(270 50 50)">
  <rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#fe718d">
    <animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="-0.16666666666666666s" repeatCount="indefinite"></animate>
  </rect>
</g><g transform="rotate(300 50 50)">
  <rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#fe718d">
    <animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="-0.08333333333333333s" repeatCount="indefinite"></animate>
  </rect>
</g><g transform="rotate(330 50 50)">
  <rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#fe718d">
    <animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="0s" repeatCount="indefinite"></animate>
  </rect>
</g>
<!-- [ldio] generated by https://loading.io/ --></svg>

Some pictures are converted to base64

Base64 is a way to represent binary data based on 64 printable characters.


Converting some pictures to base64 encoding can reduce the pressure of network request and picture server, which is good for page loading.

Compress html, css, js and other static resources

When we write code, we often use indentation and newline, which increases the volume of code file invisibly.


In the same network situation, the smaller the size of our code, the faster users can load our web pages.


Before html and css are published to online version, we can delete all indentation and line feed of the code, so as to reduce the code volume. Such as "Zhihu":





Before js is released to the online version, we can delete all indents and newlines of the code, and replace all variable names and method names with shorter words to reduce the code volume. Such as "Zhihu":


CDN

CDN(Content Delivery Network) refers to content distribution network, also known as content delivery network. The concept began in 1996 and was proposed by a research group of Massachusetts Institute of technology to improve the service quality of the Internet.





We deploy html, css, js, icon, font, video, music and other static resources to each node of cdn, which can greatly optimize the network request speed of users in different regions and different network operators.

Gzip

Gzip encoding over HTTP protocol is a technology used to improve the performance of WEB applications. WEB sites with large traffic often use gzip compression technology to make users feel faster.


Use Gzip compression to compress the file size by nearly two-thirds:


- RZeeY

Topics: Javascript network encoding xml