search
HomeWeb Front-endHTML TutorialHow to better reduce page loading time

How to better reduce page loading time

Jul 17, 2017 pm 03:08 PM
loadmethod

  1. How to better reduce page loading time, 19 methods are provided below, for reference only, interested friends can take a look.

  2. 1. The number of repeated HTTP requests should be reduced as much as possible

(1) Reduce the number of calls to other pages and files.

 (2) Sprite diagram

2. Place the definition of css style in the header of the file

This setting is suitable for users with slow network or large web page content. The situation is more favorable, and the format information can be maintained while the web page is gradually rendered, without affecting the beauty of the web page.

3. Put Javascript script at the end of the file

4. Compress Javascript and CSS code

5. Use CDN (Content Delivery Network) network acceleration

There are many companies doing CDN acceleration business in China. To put it simply, it is to spread your pictures and videos to places that 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. Doing this , while reducing the load on your own website.

6. Enable gzip compression function on the server
After compressing the files to be transferred and then transferring them to the client and then decompressing them, the amount of data transmitted over the network will be greatly reduced. Apache and Nginx on the server can be enabled directly. You can also use code to directly set the transmission file header and add gzip settings. You can also set it directly from the load balancing device. However, it should be noted that this setting will slightly increase the load on the server. Websites whose server performance is not very good should be carefully considered.

7. Ajax uses cache calling
Ajax calls all use cache calling, and are generally implemented using additional feature parameters. Pay attention to

{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 downloaded again or the information will be updated.

8. Try to use the GET method for Ajax calls

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

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

10. Reduce the use of iframes and try not to use them if unnecessary

11. Reasonable Using Flush

After the client sends browsing requests, the server generally takes 200-500ms to process these requests. During this period, the client 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 ready content to the client. This is easy to implement in PHP. For example:

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

12. Avoid using 301 and 302 redirection

When the browser, When a "crawler" sent by a proxy or search engine makes a request for a page or URL, the web server where the calling page or URL is located will check a file named .htaccess. This file contains instructions on how to handle specific requests and plays a key role in security. Users can modify this file to notify the browser, agent or "crawler" whether the called page is temporarily removed (302 redirect) or permanently removed (301 redirect). We can also implement 301/302 permanent redirects through web hosting services instead of .htaccess' files.

13. 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 use the resize method on the web page. Although the image you see in this way is smaller in appearance, the amount of data loaded has not been reduced at all.

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.

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

15. Use multiple domain names to load multiple files and pictures in a web page

Some data indicate that during the web page loading process, IE loads the same domain name at the same time. The maximum number of parallel HTTP requests 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, such as the 19th floor, Its js files use independent domain names. It is said that Baidu has more than 20 image servers.

16. css and javascript should be called externally

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

17. Reduce DCOM elements as much as possible

Reduce the number of various elements in the web page as much as possible. For example,

is very redundant, and we can completely use < ;div>replaces it.

18. Avoid using CSS scripts (CSS Expressions)

Sometimes in order to dynamically change css parameters, css expression may be used to achieve this, but this will outweigh the gains and losses and will cause the user browser to The burden is obviously increased, so it is not recommended to do this. If changes are needed, you can use Javascript scripts to achieve it.

19. Add file expiration or cache header

For images and Js script files that are frequently accessed by the same user, you can set the buffering time in Apache or Nginx, such as setting a 24-hour expiration time, so that the user can access the When you visit again after passing this page, the same set of pictures or JS will not be downloaded again, thus reducing HTTP requests, user access speed is obviously improved, and the server load will also be reduced.

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;#Set 30 days expiration
}
location ~ .*\.(js|css)?$
{
expires 1h;#Set 1 hour expiration
}


The above is the detailed content of How to better reduce page loading time. For more information, please follow other related articles on the PHP Chinese website!

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 vs. CSS vs. JavaScript: A Comparative OverviewHTML vs. CSS vs. JavaScript: A Comparative OverviewApr 16, 2025 am 12:04 AM

The roles of HTML, CSS and JavaScript in web development are: HTML is responsible for content structure, CSS is responsible for style, and JavaScript is responsible for dynamic behavior. 1. HTML defines the web page structure and content through tags to ensure semantics. 2. CSS controls the web page style through selectors and attributes to make it beautiful and easy to read. 3. JavaScript controls web page behavior through scripts to achieve dynamic and interactive functions.

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.

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
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

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.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!