How to reduce memory usage and CPU usage of web pages

How to reduce memory usage and CPU usage of web pages

Some web pages may not look large but may be very slow to open, while others may be very long but smooth to use, which is affected by the memory and CPU used in the user's computer.

Browser issues. Each browser has its own memory issues that can affect it, but there is almost no way to control it. On Windows:

For IE series, the amount of refresh recycling is not large, but minimization will release memory.
Firefox 2 is said to also recycle when minimized, but I have never seen the most garbage. It uses as much as it can and basically does not recycle. It is said that prototype's ajax will cause memory to continue to increase.
Opera is the best. Always well controlled. There is no problem. .
The memory allocation mechanism of Linux is different from that of Win. It uses as much memory as possible. If the browser occupies all the memory, it may crash the system.

Page problem: The browser will consume memory and CPU when rendering the page, so reduce it as much as possible.

Use DocType structurally to tell the browser what you are using. HTML4 also has DTD. Maybe Transitional is more suitable for you. If you use XHTML and keep a good structure, remember to output the corresponding MIME and XML headers 1, which can reduce the browser's code inspection.
Keep the structure intact and don't let the browser complete the code for you.
To control the file size of the page, you can use the program to indent the code to make it more comfortable to read. 2~3K is also the size.
Iframe will generate a new page. In fact, there are many ways to replace iframe.
The introduced JS and CSS can be merged appropriately, and the background images can also be merged. Some people even merge Flash. Adding width attributes to content images/Objects with known width and height can reduce partial re-rendering of the page. In most cases, the only difference between 99 and 70 quality jpgs is the file size. The same is true for gif, especially small icons. The difference between 256 colors and 128 colors is the file size.
Flash moves too fast and consumes a lot of CPU. The number of frames per second and the animation effect can be reduced. If the quality is set to medium or low, a lot of resources will be saved, but this will sacrifice the effect. . Sometimes it is more appropriate to select Autolow2 or Autohigh for the quality attribute. There is no need to always select low or best.
Flash uses vector graphics to save file size, but it uses the CPU to calculate complex graphics and animations. Too many complex filters will take up a lot of memory, blur filters can reduce this.
IE filters also take up a lot of memory and also have compatibility issues. Full-screen translucency is very resource-intensive.
A 2*2 image is about the same size as an 8*8 image, but a 2*2 tiled background takes up much more space.
GIF animation also has the concept of frames, so don't treat GIF as Flash.
Don't import the entire prototype or jQuery just to use a $() behavior, they have more functions.
AJAX is cool. However, using XML will require an XML parser. Some people recommend using JSON, but this requires eval data. In fact, you can directly import the script that is already an object. You just need to pass an extra object name, or hardcode the object name, or use it directly as a function like flickr does, jsonFlickrApi({"xxx":"xxx"}), haha.
Don't use display:none when visibility:hidden can solve certain effects.
It doesn't make much sense to emphasize here that JS variables should pay attention to global and local, etc. The complexities of JS cannot be explained in just a sentence or two. Let's pay attention to Yueying's new book that is being published. ^^
In fact, a lot of the content here is similar to how to quickly present our web pages, but that article focuses on processing the server. But in many cases, saving server resource consumption will also save client resource consumption.

In fact, this article has been in the draft box for a long time, and I haven't had time to organize it. What I give you now is not complete, because it is not complete yet. I will add to it slowly.


--------------------------------------------------------------------------------

Problem: Although it may cause browser mode problems, the problem can be solved. Refer to Serving up XHTML with the correct MIME type. The browser will not display the XML header correctly, and the incorrect structure will cause the entire page to fail to display.
Autolow: Prioritizes speed, but also tries to improve appearance when possible. When playback starts, anti-aliasing is turned off. If Flash Player detects that the processor can handle anti-aliasing, it turns on the feature.
Autohigh: Initially, both playback speed and appearance are given equal weight, and when necessary, appearance will be sacrificed to ensure playback speed. When playback begins, anti-aliasing is turned on. If the actual frame rate drops below the specified frame rate, anti-aliasing is turned off to increase playback speed. Use this setting to emulate the Anti-Alias ​​command (View > Preview Mode > Anti-Alias).
Blur filter: When using blur filters, if the values ​​used for blurX and blurY are integer powers of 2 (such as 2, 4, 8, 16, and 32), the calculation speed can be accelerated and performance can be improved by 20% to 30% (Flash help says so).

<<:  CSS adaptive layout realizes the overall centering of sub-element items and left alignment of internal items

>>:  Detailed explanation of how tomcat calls Servlet initialization from source code analysis

Recommend

5 things to note when writing React components using hooks

Table of contents 01. Use useState when render is...

How to create a flame effect using CSS

The main text starts below. 123WORDPRESS.COM Down...

How to automatically import Vue components on demand

Table of contents Global Registration Partial Reg...

Detailed explanation of efficient MySQL paging

Preface Usually, a "paging" strategy is...

How to use Nginx to proxy multiple application sites in Docker

Preface What is the role of an agent? - Multiple ...

How to use CSS media query aspect-ratio less

CSS media query has a very convenient aspect rati...

Web front-end development course What are the web front-end development tools

With the development of Internet technology, user...

Step by step guide to build a calendar component with React

Table of contents Business Background Using Techn...

Ubuntu 15.04 opens mysql remote port 3306

Ubuntu 15.04 opens MySQL remote port 3306. All th...

How to understand the difference between ref toRef and toRefs in Vue3

Table of contents 1. Basics 1.ref 2. toRef 3. toR...

React passes parameters in several ways

Table of contents Passing parameters between pare...

Docker Compose installation and usage steps

Table of contents 1. What is Docker Compose? 2. D...

Sublime / vscode quick implementation of generating HTML code

Table of contents Basic HTML structure Generate s...