How to improve website loading speed by preloading (Preload) key resources

Preloading allows you to specify resources (such as fonts, images, JavaScript, and CSS) that are needed immediately or quickly during page loading. On every page of your website...Add one at the top of the sectionlink rel='preload'Label.

For example:

 

When you open a web page, the browser requests the HTML document from the server, parses its contents, and submits a separate request for the referenced resource. As a developer, you know all the resources the page needs and which resources are the most important. You can use this knowledge to request critical resources in advance to speed up the loading process. This article describes how to use theTo achieve this goal.

How preloading works

Preloading is best suited for resources that browsers usually discover later.

How to improve website loading speed by preloading (Preload) key resources1

In this case, the Pacifico font is passed through the stylesheet@font-faceDefined by rules. The browser loads the font file only after it has finished downloading and parsing the stylesheet.

By preloading a resource, you want the browser to get the resource earlier than you normally find it, because you think it is important to the current page.

How to improve website loading speed by preloading (Preload) key resources2

In this case, the Pacifico font is preloaded, so the download occurs in parallel with the stylesheet.

The key request chain represents the order in which the browser prioritizes and acquires resources. Lighthouse identifies the assets at the third layer of the chain as those discovered later. You can use the preload key request audit to determine which resources to preload.

How to improve website loading speed by preloading (Preload) key resources3

You can add to the header of the HTML document withrel="preload"OfTag to preload resources:

 

The browser caches preloaded resources so that they are available immediately when needed. (it does not execute scripts or apply style sheets. )

After preloading, many websites, including Shopify, Financial Times, and Treebo, have achieved an one-second improvement in user-centric metrics such as Time to Interactive and First Contentful Paint.

Browsers execute things such aspreconnectAndprefetchWait for resource prompts. On the other hand,preloadIt is mandatory for browsers. Modern browsers are already very good at prioritizing resources, which is why they are used cautiouslypreloadAnd preloading only the most critical resources is as important.

loadA console warning in Chrome is triggered approximately 3 seconds after the event.

How to improve website loading speed by preloading (Preload) key resources4

Supported by all modern browserspreload.

Helps to fix the following two types of warnings:

1. Preload key request

Preloading critical requests is a common warning for Web fonts. Font Awesome is a very common font that you may see.

How to improve website loading speed by preloading (Preload) key resources5

Preload key requests

two。 Render blocking resources

With preloading, you can also fix render blocking resource warnings because assets are loaded in a non-blocking manner.

How to improve website loading speed by preloading (Preload) key resources6

Eliminate rendering blocking resources

It can also help reduce maximum content rendering (LCP) time if you are preloading an image.

Preloadable resources

There are many different resources that can be preloaded.

Public resources

  • fontFont file
  • script: JavaScript file.
  • style: CSS style sheet.
  • image: image file (.jpg,.png,.webp).

Other resources

  • audioAudio files
  • documentDesigned to be created byOrEmbedded HTML document.
  • embedTo embed intoThe resources in the element.
  • fetchResources to access through fetch or XHR requests, such as ArrayBuffer or JSON files
  • objectTo embed intoThe resources in the element.
  • track: WebVTT file.
  • worker: an JavaScript network worker or shared worker.
  • videoVideo file
  • Note: at the time of this writing, there is an unresolved bug in Chrome, where preloaded requests are fetched faster than other higher priority resources. Before resolving this issue, notice how preloaded resources "skip the queue" and are requested earlier than it should be.

    Preload resources defined in CSS

    Until the browser downloads and parses the CSS files, you will not find that the@font-faceThe font or background image defined by the rule. Preloading these resources ensures that you get the CSS files before downloading them.

    Preload CSS fil

    If you use the key CSS method, the CSS will be divided into two parts. The key CSS required to render the contents of the first screen is inlined in the document'sNon-critical CSS usually uses JavaScript to delay loading. Waiting for JavaScript execution before loading a non-critical CSS can cause delays when the user scrolls, so it is best to use theStart the download faster.

    Preload JavaScript fil

    Because browsers do not perform preloaded files, preloading helps separate fetch from execution, which improves metrics such as Time to Interactive. Preloading works best if you split the JavaScript package and preload only the key blocks.

    How to realize rel=preload

    RealizepreloadThe easiest way is in the documentAdd aTag:

      

    ProvideasProperty helps the browser set the priority of the prefetched resource based on its type, set the correct header, and determine whether the resource already exists in the cache. Acceptable values for this property are:scriptstylefontAndimageWait.

    Check the Chrome Resource Priorities and Scheduling documentation to learn more about how browsers prioritize different types of resources.

    Note: omitasProperty or uses an invalid value, which is equivalent to a XHR request, where the browser does not know what it gets and cannot determine the correct priority. It may also cause some resources, such as scripts, to be fetched twice.

    Some types of resources, such as fonts, are loaded in anonymous mode. For these resources, you must set thepreloadOfcrossoriginAttributes:

        

    Note: no settingscrossoriginThe preloaded font of the property will be obtained twice!

    In addition,The element also acceptstypeProperty that contains the MIME type of the linked resource. Browser usagetypeProperty to ensure that resources are preloaded only if their file types are supported. If the browser does not support the specified resource type, it ignores the.

    Try to improve web page performance by preloading web fonts.

    You can use theLinkThe HTTP header preloads any type of resource:

    Link: /style.css>;; as="style"

    Specify in the HTTP headerpreloadOne of the benefits is that browsers do not need to parse the document to find it, which can provide some small improvements in some cases.

    Preload the JavaScript module using webpack

    If you use the module baler that creates the application build file, you need to check that it supports the injection of preloaded tags. In webpack 4. 6. 0 or later, it passes through theimport()Support for preloading using magic comments (magic comments) in:

    import(_/* webpackPreload: true */_ "CriticalChunk")

    If you are using an older version of webpack, use a third-party plug-in, such as preload-webpack-plugin.

    Things to keep in mind when preloading

    • Do not preload every script, or it will actually cause performance problems, such as increasing the total blocking time (TBT). Preloading should be used only for resources that are immediately needed, so they are loaded in a non-blocking manner. This is commonly used for web fonts, images, CSS, and JS.
    • If you are using cache cleanup techniques such as query stringsdomain.com/style.css?ver=1.0Don't forget that the browser will see the exact URL. Therefore, you will need to use the query string URL, or you can use handles to dynamically preload.
    • If you have a URL that CDN overrides your assets, make sure that all resources that you want to preload are rewritten correctly first. If the URL does not match, you may end up loading the resource twice.
    • If you preload stylesheets (CSS) or scripts (JS) and you are using plug-ins to combine your CSS/JSS (Autoptimize, WP Rocket, and so on), be sure to exclude your preloaded resources from the connection process. Otherwise, it may be packaged twice and eventually put more code on your site.

    Summary

    To improve the speed of the web page, preload the browser to find important resources that are later. Preloading all resources can be counterproductive, so use it with cautionpreloadAnd measure its impact in reality.

    via https://web.dev

    Disclaimer: All articles on this website, unless otherwise specified or marked, are original and published on this website. Any individual or organization is prohibited from copying, stealing, collecting, or publishing the content of this site to any website, book, or other media platform without the consent of this site. If the content on this website infringes on the legitimate rights and interests of the original author, you can contact us for assistance.
    1. Can free downloads or VIP membership resources be directly commercialized?
      All resources on this site are copyrighted by the original author. The resources provided here can only be used for reference and learning purposes. Please do not use them for commercial purposes. If copyright disputes arise due to commercial use, all responsibilities shall be borne by the user. For more instructions, please refer to the VIP introduction.
    2. Prompt to download but unable to decompress or open?
      The most common situation is incomplete download: you can compare the capacity of the downloaded compressed file with the capacity on the network disk. If it is less than the capacity indicated by the network disk, this is the reason. This is a bug downloaded from the browser. It is recommended to use Baidu Netdisk software or Xunlei to download. If this situation is ruled out, you can leave a message at the bottom of the corresponding resource or contact us.
    3. Can't find the example images in the material resource introduction article?
      For member exclusive, full site source code, program plugins, website templates, webpage templates, and other types of materials, the images used for introduction in the article are usually not included in the corresponding downloadable material package. These related commercial images need to be purchased separately, and our website is not responsible (nor can we) for finding the source. Similarly, some font files also have this situation, but some materials will have a list of font download links in the material package.
    4. Unable to display download address or view content after payment?
      If you have successfully made the payment but the website does not display a success prompt, please contact the webmaster to provide payment information for you to process
    5. Can I get a refund after purchasing this resource?
      The source code materials belong to virtual commodities, which are replicable and communicable. Once granted, no form of refund or exchange requests are accepted. Please confirm that it is the resource you need before purchasing and obtaining it

    It is a powerful Wordpress resource mall theme that supports many functions such as paid downloads, paid playback of audio and video, and paid viewing.

    Quick Navigation

    About this site

    Contact Us

    If there are any bugs or suggestions, you can contact us online or log in to our website account to enter the personal center to submit a work order.
    Copyright © 2024 Envatoshops - All rights reserved