search
HomeWeb Front-endHTML TutorialWeb front-end optimization methods

Web front-end optimization methods

Dec 06, 2016 am 09:44 AM
JavaScriptcss

At present, the Internet BS model applications are becoming more and more widespread, including the development of website systems, OA platforms, etc. So how to do it well, do it well, and bring a good experience to users? Let me share with you my experience in Web front-end optimization. These experiences are more practical technologies in work practice
1. Minimize the number of HTTP requests - a trade-off must be made

Merge images (such as css sprites, built-in image usage data) , Merging CSS and JS is very important, but the size of the merged file must be considered.

  2. Specify Expires or Cache-Control for the file header to make the content cacheable.

  Distinguish between static content and dynamic content to avoid unnecessary HTTP requests in future page visits.

  3. Avoid empty src and href

Pay attention to tags with these two attributes such as link, script, img, iframe, etc.;

4. Use gzip to compress content

Gzip compresses all possible file types to reduce files Volume

  5. Put CSS at the top

  to achieve orderly loading of the page. This is more important for pages with more content and users with slow network speeds. At the same time, the HTML specification clearly states that the style sheet should be placed Contained within the area of ​​the page;

 6. Put JS at the bottom

 The HTTP/1.1 specification recommends that the browser should download no more than two contents in parallel for each host name. The problem is that the script prevents the parallel downloading of the page. Even if the host names are different

 7. Avoid using CSS expressions

 When the page is displayed and zoomed, scrolled, or even moved the mouse, we should pay attention to the calculation frequency of CSS expressions. Consider one-time expressions or use event handlers instead of CSS expressions.

 8. Put CSS and JS into external files

  We need to weigh the compromise between the reduction in HTTP requests brought by the built-in code and the benefits of caching by using external files.

 9. Streamline CSS and JS

 The purpose is to reduce the size of downloaded files. You can consider compression tools JSMin and YUI Compressor.

 10. Eliminate duplicate JS and CSS

  Repeated calls to the script will not only add additional HTTP requests, but also waste time in multiple operations. In IE and Firefox, regardless of whether the script is cacheable or not, they all have the problem of re-evaluating JavaScript.

  11. Make AJAX cacheable

Utilize timestamps to achieve a more sophisticated response cache and update the server data synchronously.

  12. Flush the output buffer as early as possible

Especially for css, parallel download of js files is more meaningful

13. Use GET to complete AJAX requests

When using XMLHttpRequest, the POST method in the browser is a "two-step" "Go" process: first send the file header, and then send the data. It makes more sense when using GET to get data when the url is less than 2K.

 14. Lazy loading

 After confirming that the page is running normally, load the script to implement things such as drag-and-drop and animation, or hide part of the content and fold the content.

 15. Preloading

  Pay attention to unconditional loading, conditional loading and expected loading.

  16. Minimize the number of iframes

Consider that even if the content is empty, loading will take time, which will prevent the page from loading and has no semantic meaning. Note that iframe has an overhead that is 1-2 orders of magnitude higher than other DOM elements. It will In the typical way of blocking the onload event, the main page stylesheet in IE and Firefox will block its download.

 17. Avoid 404

 HTTP request time consumption is very large. Some sites change the 404 error response page to "Are you looking for *". Although this improves the user experience, it also wastes server resources (such as database, etc.).

 18. Reduce the size of cookies

 Remove unnecessary cookies, make the cookie size as small as possible to reduce the impact on user response, and set a reasonable expiration time. Expiration time earlier and not clearing cookies too early will improve user response time.

 19. Optimize images

  Try converting GIF format to PNG format to see if it saves space. Run pngcrush (or other PNG optimization tools) on all PNG images

20. Don’t scale images in HTML – a trade-off

Don’t use images that are larger than necessary to set the height and width in HTML.

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
Are the HTML tags and elements the same thing?Are the HTML tags and elements the same thing?Apr 28, 2025 pm 05:44 PM

The article explains that HTML tags are syntax markers used to define elements, while elements are complete units including tags and content. They work together to structure webpages.Character count: 159

What is the significance of <head> and <body> tag in HTML?What is the significance of <head> and <body> tag in HTML?Apr 28, 2025 pm 05:43 PM

The article discusses the roles of <head> and <body> tags in HTML, their impact on user experience, and SEO implications. Proper structuring enhances website functionality and search engine optimization.

What is the difference between <strong>, <b> tags and <em>, <i> tags?What is the difference between <strong>, <b> tags and <em>, <i> tags?Apr 28, 2025 pm 05:42 PM

The article discusses the differences between HTML tags , , , and , focusing on their semantic vs. presentational uses and their impact on SEO and accessibility.

Please explain how to indicate the character set being used by a document in HTML?Please explain how to indicate the character set being used by a document in HTML?Apr 28, 2025 pm 05:41 PM

Article discusses specifying character encoding in HTML, focusing on UTF-8. Main issue: ensuring correct display of text, preventing garbled characters, and enhancing SEO and accessibility.

What are the various formatting tags in HTML?What are the various formatting tags in HTML?Apr 28, 2025 pm 05:39 PM

The article discusses various HTML formatting tags used for structuring and styling web content, emphasizing their effects on text appearance and the importance of semantic tags for accessibility and SEO.

What is the difference between the 'id' attribute and the 'class' attribute of HTML elements?What is the difference between the 'id' attribute and the 'class' attribute of HTML elements?Apr 28, 2025 pm 05:39 PM

The article discusses the differences between HTML's 'id' and 'class' attributes, focusing on their uniqueness, purpose, CSS syntax, and specificity. It explains how their use impacts webpage styling and functionality, and provides best practices for

What is the 'class' attribute in HTML?What is the 'class' attribute in HTML?Apr 28, 2025 pm 05:37 PM

The article explains the HTML 'class' attribute's role in grouping elements for styling and JavaScript manipulation, contrasting it with the unique 'id' attribute.

What are different types of lists in HTML?What are different types of lists in HTML?Apr 28, 2025 pm 05:36 PM

Article discusses HTML list types: ordered (<ol>), unordered (<ul>), and description (<dl>). Focuses on creating and styling lists to enhance website design.

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!