![](/img/trans.png)
[英]Can I “pre-load” an image with JS to be used as a CSS background-image?
[英]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。
在 Safari 但是我能得到的只是:
這清楚地表明 Safari 沒有嘗試異步加載腳本,而是等待收到完整的 html 響應。
我錯過了什么? safari 是否根本不進行任何資產預加載?
目前, Safari 不支持<link rel=preload>
,這解釋了您所看到的瀑布。 好消息是,他們的 Web 布道者之一 Jen Simmons在 Twitter 上詢問了如果它存在,開發人員會使用它做什么。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.