1. 程式人生 > >Preload, Prefetch And Priorities in Chrome

Preload, Prefetch And Priorities in Chrome

Don’t rely on fetch() working with “preload”… just yet. In Chrome if you try to use preload with the fetch() API you will end up triggering a double download. This doesn’t currently occur with XHR and we have an open bug to try addressing it.

Supply an “as” when preloading or you’ll negate any benefits!

If you don’t supply a valid “as” when specifying what to preload, for example, scripts, you will end up fetching twice.

Preloaded fonts without crossorigin will double fetch! Ensure you’re adding a crossorigin attribute when fetching fonts using preload otherwise they will be double downloaded. They’re requested using anonymous mode CORS. This advice applies even if fonts are on the same origin as the page. This is applicable to other anonymous fetches too (e.g XHR by default).

Resources with an integrity attribute can’t reuse preloaded resources (for now) and can also cause double fetches. The `integrity` attribute for link elements has not yet been implemented and there’s an open spec issue about it. This means the presence of any integrity metadata will currently discard preloaded resources. In the wild, it can also result in duplicate requests where you have to make a trade-off between security and performance.

Finally, although it won’t cause double fetches, this is generally good advice:

Don’t try preloading absolutely everything! Instead, select specific late discovered resources that you want to load earlier and use preload to tell the browser about them.

Should I just preload all the assets that my page requests in the head? Is there a recommended limit like “only preload ~6 things”?

This is a good example of Tools, not rules. How much you preload may well factor in how much network contention you’re going to have with other resources also being loaded on your page, your user’s available bandwidth and other network conditions.

Preload resources that are likely to be discovered late in your page, but are otherwise important to fetch as early as possible. With scripts, preloading your key bundles is good as it separates fetching from execution in a way that just using say, <script async> wouldn’t as it blocks the window’s onload event. You can preload images, styles, fonts, media. Most things — what’s important is that you’re in better control of early-fetching what you as a page author knows is definitely needed by your page sooner rather than later.

Does prefetch have any magical properties you should be aware of? Well, yes.

In Chrome, if a user navigates away from a page while prefetch requests for other pages are still in flight, these requests will not get terminated.

Furthermore, prefetch requests are maintained in the unspecified net-stack cache for at least 5 minutes regardless of the cachability of the resource.

I’m using a custom “preload” implementation written in JS. How does this differ from rel=”preload” or Preload headers?

Preload decouples fetching a resource from JS processing and execution. As such, preloads declared in markup are optimized in Chrome by the preload scanner. This means that in many cases, the preload will be fetched (with the indicated priority) before the HTML parser has even reached the tag. This makes it a lot more powerful than a custom preload implementation.

Wait. Shouldn’t we be using HTTP/2 Server Push instead of Preload?

Use Push when you know the precise loading order for resources and have a service worker to intercept requests that would cause cached resources to be pushed again. Use preload to move the start download time of an asset closer to the initial request — it’s useful for both first and third-party resources.

Again, this is going to be an “it depends”. Let’s imagine we’re working on a cart for the Google Play store. For a given request to play.google.com/cart:

Using Preload to load key modules for the page requires the browser to wait for the play.google.com/cart payload in order for the preload scanner to detect dependencies, but after this contains sufficient information to saturate a network pipe with requests for the site’s assets. This might not be the most optimal at cold-boot but is very cache and bandwidth friendly for subsequent requests.

Using H/2 Server Push, we can saturate the network pipe right away on the request for play.google.com/cart but can waste bandwidth if the resources being pushed are already in the HTTP or Service Worker cache. There are always going to be trade-offs for these two approaches.

Although Push is invaluable, it doesn’t enable all the same use-cases as Preload does.

Preload has the benefit of decoupling download from execution. Thanks to support for document onload events you can control scripting if, how and when a resource gets applied. This can be powerful for say, fetching JS bundles and executing them in idle blocks or fetching CSS and applying them at the right point in time.

Push can’t be used by third-party hosted content. By sending resources down immediately, it also effectively short-circuits the browser’s own resource prioritization logic. In cases where you know exactly what you’re doing, this can yield performance wins, but in cases where you don’t you could actually harm performance significantly.

What is the Link preload header? How does it compare to the preload link tag? And how does it relate to HTTP/2 Server Push?

As with other types of links, a preload link can be specified using either an HTML tag or an HTTP header (a Link preload header). In either case, a preload link directs the browser to begin loading a resource into the memory cache, indicating that the page expects with high confidence to use the resource and doesn’t want to wait for the preload scanner or the parser to discover it.

When the Financial Times introduced a Link preload header to their site, they shaved 1 second off the time it took to display the masthead image:

相關推薦

Preload, Prefetch And Priorities in Chrome

Don’t rely on fetch() working with “preload”… just yet. In Chrome if you try to use preload with the fetch() API you will end up triggering a double downlo

Tips and Tricks for Debugging in chrome

Tips and Tricks for Debugging in chrome Pretty print On sources panel ,clicking on the {} on the bottom left hand side. Console.table Display data as a

[PWA] Add Push Notifications to a PWA with React in Chrome and on Android

On Android and in Chrome (but not on iOS), it's possible to send push notifications with a PWA. We'll start by asking the user for permission to send them

[Preact] Use State and Props in the Component Render Function

cnblogs use method nic imp ima rop component end Preact offers, in addition to the regular component API from React, the ability to acces

Relationship between frequency and spatial in digital images

log 兩個 表示 title cal .com 關系 show tla 今天又復習了一遍<<Digital Image Processing>>的第四章,為了加深對頻域的理解,我自己用PS畫了一張圖。如下: 然後做FFT,得到頻譜圖如下:

About the diffrence of wait timed_wait and block in java

@override stack util except str void rgs dex interrupt import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.Reentra

【轉】Redundancy and Latency in Structured Buffer Use

list set actual about ast oat efi macros cte From:https://developer.nvidia.com/content/redundancy-and-latency-structured-buffer-use In a

Authentication and Authorization in ASP.NET Web API

module to server -h alter prop strong bar isa som ?You‘ve created a web API, but now you want to control access to it. In this series o

解決author波浪線Spellchecker inspection helps locate typos and misspelling in your code, comments and literals, and fix them in one click

博客 翻譯 cli 修復 and idea tro alt 拼寫檢查 自從把默認的頭註釋的author改成自己的名字以後越看越順眼,但是發現名字下面一直有個波浪線,強迫癥簡直不能忍。 然後當你把鼠標放上去,再點擊提示上的“more”,會看到下面的提示: Spellchec

The Usage of Lambda and Heap in the C++ STL

ner class eap cto con c++ stl nts been nta The Usage of Lambda and Heap in the C++ STL Heap In c++ STL, the heap had been implemented as

sap.ui.require in SAP UI5 and require in nodejs

代碼 fin 同事 upload gem OS modules 公眾 ont UI5 例如我需要在controller的onShowHello裏通過MessageToast彈一個消息顯示在UI上, 我需要先定義我自己的controller,該controller exte

JavaScript and Ruby in ABAP

ABAP. Java JavaScript Ruby SAP Netweaver裏有個mini JavaScript engine CL_JAVA_SCRIPT, 對於Js code的編譯和執行都是用system call完成。 只能當玩具用:report SJSEU 執行結果:120

833. Find And Replace in String

neo bsp overlap nbsp source and there bec enc Find And Replace in String To some string S, we will perform some replacement operations th

Qualcomm platform, the commonly used parameters of charger and battery in device tree file

inpu res alc max stc sum In nat TE 1 battery charging voltage : qcom,float-voltage-mv = <0x10fe>; 2 battery recharge threshold : qc

Python文件運行時報TabError: inconsistent use of tabs and spaces in indentation

運行時 erro space 導致 error: con 地方 錯誤 ace 1. 問題描述 Python文件運行時報TabError: inconsistent use of tabs and spaces in indentation 2. 問題原因 tab 和 spa

Edge-assisted Tra?ic Engineering and applications in the IoT

exist ability put 無需 位置 組成 power already 安裝 物聯網中邊緣輔助的流量工程和應用 本文為SIGCOMM 2018 Workshop (Mobile Edge Communications, MECOMM)論文。 筆者翻譯了該論文。由於

[Analytics] Add Tealium debugger in Chrome

analytic document app random inf ive alt -s then It would be helpful once you can see what information have been tracking inside yo

Codeforces 781D Axel and Marston in Bitland 矩陣 bitset

多少 tchar 當前 digi con names include [1] ORC 原文鏈接https://www.cnblogs.com/zhouzhendong/p/CF781D.html 題目傳送門 - CF781D 題意   有一個 n 個點的圖,有 m 條

session store list and show in the jsp

ref http://bbs.csdn.net/topics/392169027 resolution put standard.jar and jstl.jar in web-inf/lib web.xml