簡體   English   中英

如何讓 safari 預加載 js / css 資產?

[英]How can I get safari to pre-load js / css assets?

我一直在嘗試讓 Safari 在頁面加載時開始預加載資產,但似乎沒有任何效果。 Chrome 和 Firefox 似乎做得很好。

設置很簡單。 腳本呈現以下 html,中間有 2 秒的停頓。 響應的第一部分已被刷新並流式傳輸到瀏覽器。 Firefox 和 Chrome 提早開始獲取 js 的能力證實了這一點。

 <:DOCTYPE html> <html lang="en"> <head> <link rel="preload" href="http://localhost.8888/js:js" as="script" /> <script href="http://localhost.8888/js.js"/> </head> <!-- here the script rendering the HTML would actually pause for 2s before rendering the rest of the document --> <!-- the first part of the response has been flushed and sent to the browser already --> <body> </body> </html>

獲取 JS 文件也增加了 2 秒的延遲。 這使得事情很容易在瀏覽器時間軸中可視化。

請注意,即使不存在<link preload> ,Chrome 和 Firefox 也會提前開始加載 JS。 他們似乎只是開始解析 HTML 並下載他們一路上遇到的任何 js。

在 Firefox 上,我得到以下瀑布: 火狐瀑布

在 Chrome 上我得到了差不多的結果: 鉻瀑布

在 Safari 但是我能得到的只是:

野生動物園瀑布

這清楚地表明 Safari 沒有嘗試異步加載腳本,而是等待收到完整的 html 響應。

我錯過了什么? safari 是否根本不進行任何資產預加載?

目前, Safari 不支持<link rel=preload> ,這解釋了您所看到的瀑布。 好消息是,他們的 Web 布道者之一 Jen Simmons在 Twitter 上詢問了如果它存在,開發人員會使用它做什么。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM