search
HomeWeb Front-endHTML TutorialHow to effectively reduce web page loading time? _html/css_WEB-ITnose

Netizens don’t like to spend too much time waiting for the web page to open. The longer they wait, the user may close the web page directly, which will lose a lot of traffic! Secondly, the ranking of keywords is also related to the opening speed of web pages. This mainly reflects the user experience of search engines. If the user experience is good, the ranking will be better than other websites. Therefore, I think it is necessary for us to improve the opening speed of web pages. This does not require too much cost investment, just pay more attention to some tips! Below are 20 ways to help you improve website access speed and shorten web page loading time .

1. Reduce the number of page HTTP requests

A more straightforward understanding is to reduce the number of calls to other pages and files.

A. When we use CSS format control, we often use background to load many graphic files. Each background image generates at least one HTTP request. Generally, we use background extensively in order to make the page lively. To load the background image, to improve this situation, you can use a useful background-position attribute of CSS to load the background image. We combine multiple images that need to be loaded frequently into a single image. When it needs to be loaded, use the following Form loading can reduce the HTTP request for loading this part of the image to 1.

B. Use Image maps. This method is also commonly used, but it is limited to the same area.

C.Inline images, this method is rarely seen, but it is very practical for small and simple images.

2. Use CDN (Content Delivery Network) network acceleration

There are many companies doing CDN acceleration business in China. To put it simply, it means spreading your pictures and videos Go wherever the CDN network can reach, so that users can download these files nearby when they visit, thereby achieving the purpose of speeding up the network. This can also reduce the load on your own website.

3. Add file expiration or cache header

For images, Js script files, etc. that are frequently accessed by the same user, the buffering time can be set in Apache or Nginx, such as setting 24-hour expiration time, so that when the user visits the page again, the same set of images or JS will not be downloaded again, thereby reducing HTTP requests, user access speed will be significantly improved, and the server load will also be reduced. The following is an example of cache control in nginx configuration:

4. The server turns on gzip compression

Everyone knows this well and will need to transmit it soon. The content is compressed and transmitted to the client and then decompressed, so that the amount of data transmitted on the network will be greatly reduced. Usually, Apache and Nginx on the server can directly enable this setting. You can also directly set the transmission file header from the code perspective, add gzip settings, or directly set it from the load balancing device. However, it should be noted that this setting will slightly increase the load on the server.

5. The css format definition is placed in the header of the file

This setting is more advantageous when the client is on a slow network or the web page content is relatively large. You can The web page is gradually rendered while still maintaining the format information, without affecting the beauty of the web page.

6. Put Javascript scripts at the end of the file

Many Javascript scripts have low execution efficiency, or some third-party domain name scripts unexpectedly cannot be loaded. If you put these Placing the script at the front of the page may cause the content loading speed of our own website to decrease or even fail to load normally. Therefore, these scripts are generally placed at the end of the web page file. The scripts that must be placed in the front should be replaced with the so-called The "post-loading" method is used to load the main web page after it is loaded to prevent it from affecting the loading speed of the main web page.

7. Avoid using CSS scripts (CSS Expressions)

Sometimes in order to dynamically change css parameters, you may use css expression, but this is not worth the gain. It will significantly increase the burden on the client browser, so it is not recommended. If changes are needed, Javascript can be used to implement it.

8. css and javascript should be loaded externally

If the content of css and js is relatively large, try not to write them into the same page and load them externally. It is more appropriate to enter because the browser itself will cache css and js files.

9. Compress Javascript and CSS code

Generally, there are a lot of spaces, line breaks, and comments in js and css files, which are easy to read. If they can be compressed, they will It will be very helpful for network transmission. There are many tools in this area. Generally, you can keep the development version and use the tool to generate the production version. Comparing the two files, the compression rate can generally reach more than 50%, and the amount of data reduced is quite considerable.

10. Avoid using 301 and 302 redirects

11. Develop good development and maintenance habits and try to avoid repeated calls of scripts

12. Configure ETags

13. Ajax uses cache call

For the use of this, please refer to the Discuz forum code, which uses a cache call method for a large number of Ajax calls. It is generally implemented using additional feature parameters. Pay attention to the

<script src="xxx.js?{verhash},{verhash}"

is the characteristic parameter. If this parameter does not change, the cache file will be used. If it changes, the new file will be re-downloaded or the information will be updated.

14. Use Flush properly

After the client sends a browsing request, the server generally takes 200-500ms to process these requests. During this period, the client The browser is in a waiting state. If you want to reduce the user's waiting time, you can use flush at the appropriate location to push the ready content to the user. This is easy to implement in PHP. For example:

<!--css,js--></head><?php flush();?><body>...<!--content-->

15. Try to use the GET method for Ajax calls

When actually using XMLHttpRequest, if the POST method is used, two HTTP requests will occur. Using the GET method only one HTTP request will occur. If you use the GET method instead, HTTP requests are reduced by 50%!

16. Reduce DCOM elements as much as possible

This is easy to understand, which is to reduce the number of various elements in the web page as much as possible.

17. Use multiple domain names to load multiple files and pictures in web pages

Remember that there is information that shows that during the web page loading process, IE, at the same time, The maximum number of parallel HTTP requests for the same domain name is 2. If the number of files that a web page needs to load exceeds 2 (usually far more than...), to speed up web page access, it is best to distribute the files to multiple domain names. For example, on the 19th floor, its js files use independent domain names. It is said that Baidu has more than 20 image servers.

18. Reduce the use of iframes. If necessary, try not to use them

Iframes are usually used to load content from different domain names. This may also be caused by the loading of iframe content. Speed ​​affects the loading speed of the main web page. If possible, capture the content that needs to be loaded and embed it locally. If you really need to load iframe, use post-loading method to achieve it.

19. Optimize image files

Optimize image files and reduce their size, especially thumbnails. Be sure to generate thumbnails according to size and then call them. Do not add them to the web page. It is implemented using the resize method. Although the image you see in this way is smaller in appearance, the amount of data loaded has not been reduced at all. I have seen thumbnails loaded in a web page, and their actual size is as huge as 10M...

Ordinary images and icons should also be compressed as much as possible. This can be achieved by saving web images, reducing the number of colors, etc. .

20. When the page content is large enough, it can be displayed in paging, or loaded after page turning like Taobao.

Statement
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
HTML: Is It a Programming Language or Something Else?HTML: Is It a Programming Language or Something Else?Apr 15, 2025 am 12:13 AM

HTMLisnotaprogramminglanguage;itisamarkuplanguage.1)HTMLstructuresandformatswebcontentusingtags.2)ItworkswithCSSforstylingandJavaScriptforinteractivity,enhancingwebdevelopment.

HTML: Building the Structure of Web PagesHTML: Building the Structure of Web PagesApr 14, 2025 am 12:14 AM

HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.

From Text to Websites: The Power of HTMLFrom Text to Websites: The Power of HTMLApr 13, 2025 am 12:07 AM

HTML is a language used to build web pages, defining web page structure and content through tags and attributes. 1) HTML organizes document structure through tags, such as,. 2) The browser parses HTML to build the DOM and renders the web page. 3) New features of HTML5, such as, enhance multimedia functions. 4) Common errors include unclosed labels and unquoted attribute values. 5) Optimization suggestions include using semantic tags and reducing file size.

Understanding HTML, CSS, and JavaScript: A Beginner's GuideUnderstanding HTML, CSS, and JavaScript: A Beginner's GuideApr 12, 2025 am 12:02 AM

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

The Role of HTML: Structuring Web ContentThe Role of HTML: Structuring Web ContentApr 11, 2025 am 12:12 AM

The role of HTML is to define the structure and content of a web page through tags and attributes. 1. HTML organizes content through tags such as , making it easy to read and understand. 2. Use semantic tags such as, etc. to enhance accessibility and SEO. 3. Optimizing HTML code can improve web page loading speed and user experience.

HTML and Code: A Closer Look at the TerminologyHTML and Code: A Closer Look at the TerminologyApr 10, 2025 am 09:28 AM

HTMLisaspecifictypeofcodefocusedonstructuringwebcontent,while"code"broadlyincludeslanguageslikeJavaScriptandPythonforfunctionality.1)HTMLdefineswebpagestructureusingtags.2)"Code"encompassesawiderrangeoflanguagesforlogicandinteract

HTML, CSS, and JavaScript: Essential Tools for Web DevelopersHTML, CSS, and JavaScript: Essential Tools for Web DevelopersApr 09, 2025 am 12:12 AM

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

The Roles of HTML, CSS, and JavaScript: Core ResponsibilitiesThe Roles of HTML, CSS, and JavaScript: Core ResponsibilitiesApr 08, 2025 pm 07:05 PM

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

See all articles

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MinGW - Minimalist GNU for Windows

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.