最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

web前端優(yōu)化時為什么不建議使用css @import

  發(fā)布時間:2013-12-27 15:33:05   作者:佚名   我要評論
研究web前端優(yōu)化時最多的建議就是不要使用 css @import 因為用這種方式加載css相當(dāng)于把css放在了html底部,關(guān)于這一點(diǎn)下面為大家詳細(xì)介紹下
曾經(jīng)研究web前端優(yōu)化時在網(wǎng)上多處看到這樣一條建議,大意是:

不要使用 css @import, 因為用這種方式加載css相當(dāng)于把css放在了html底部。

關(guān)于這一點(diǎn),我一直很疑惑: 為什么用@import就等于把css放在了頁面底部? 原理是什么?? 但一直不得而知,因為網(wǎng)絡(luò)文章一大抄,轉(zhuǎn)載的很多,去細(xì)究原因的卻很少。

直到今天,在google developers看一篇文章時,無意間找到了這個原因,原文如下:

Avoid CSS @import
Overview

Using CSS @import in an external stylesheet can add additional delays during the loading of a web page.
Details

CSS @importallows stylesheets to import other stylesheets. When CSS @import isused from an external stylesheet, the browser is unable to downloadthe stylesheets in parallel, which adds additional round-trip timesto the overall page load. For instance, iffirst.css contains the following content:

@import url("second.css")

The browser must download, parse, andexecute first.css before it is able to discover that itneeds to downloadsecond.css.
Recommendations

Use the <link> tag instead of CSS @import
Instead of @import, use a <link> tag for each stylesheet. This allows the browser to download stylesheets in parallel, which results in faster page load times:

<link rel="stylesheet" href="first.css">
<link rel="stylesheet" href="second.css">

我們確實(shí)要避免使用css @import, 但原因卻不是什么相當(dāng)于放在了頁面底部,而是這樣做會導(dǎo)致css無法并行下載,因為使用@import引用的文件只有在引用它的那個css文件被下載、解析之后,瀏覽器才會知道還有另外一個css需要下載,這時才去下載,然后下載后開始解析、構(gòu)建render tree等一系列操作。 星球瀏覽器在頁面所有css下載并解析完成后才會開始渲染頁面(Before a browser can begin to render a web page, it mustdownload and parse any stylesheets that are required to lay out thepage. Even if a stylesheet is in an external file that is cached,rendering is blocked until the browser loads the stylesheet from disk.),因此css @import引起的css解析延遲會加長頁面留白期。 所以,要盡量避免使用css @import而盡量采用link標(biāo)簽的方式引入。

相關(guān)文章

最新評論

石家庄市| 德惠市| 龙陵县| 兴隆县| 包头市| 德格县| 东丰县| 崇礼县| 合江县| 吉林省| 洛阳市| 闸北区| 子长县| 乳山市| 康平县| 新闻| 华安县| 浪卡子县| 共和县| 昆明市| 萨嘎县| 隆林| 金乡县| 郓城县| 樟树市| 天峻县| 新干县| 扶沟县| 大田县| 荣成市| 五大连池市| 建宁县| 东乌珠穆沁旗| 通化市| 西藏| 灵寿县| 科技| 西乡县| 金华市| 西安市| 密山市|