1. 程式人生 > >關於Chrome瀏覽器載入某些CSS檔案超慢或超時的奇葩問題的解決辦法

關於Chrome瀏覽器載入某些CSS檔案超慢或超時的奇葩問題的解決辦法

<pre name="code" class="css">/*! normalize.css v3.0.2 | MIT License | git.io/normalize */
html{font-family:sans-serif;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%}body{margin:0}article,aside,details,figcaption,figure,footer,header,hgroup,main,menu,nav,section,summary{display:block}audio,canvas,progress,video{display:inline-block;vertical-align:baseline}audio:not([controls]){display:none;height:0}[hidden],template{display:none}a{background-color:transparent}a:active,a:hover{outline:0}abbr[title]{border-bottom:1px dotted}b,strong{font-weight:bold}dfn{font-style:italic}h1{font-size:2em;margin:0.67em 0}mark{background:#ff0;color:#000}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sup{top:-0.5em}sub{bottom:-0.25em}img{border:0}svg:not(:root){overflow:hidden}figure{margin:1em 40px}hr{-moz-box-sizing:content-box;-webkit-box-sizing:content-box;box-sizing:content-box;height:0}pre{overflow:auto}code,kbd,pre,samp{font-family:monospace, monospace;font-size:1em}button,input,optgroup,select,textarea{color:inherit;font:inherit;margin:0}button{overflow:visible}button,select{text-transform:none}button,html input[type="button"],input[type="reset"],input[type="submit"]{-webkit-appearance:button;cursor:pointer}button[disabled],html input[disabled]{cursor:default}button::-moz-focus-inner,input::-moz-focus-inner{border:0;padding:0}input{line-height:normal}input[type="checkbox"],input[type="radio"]{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;padding:0}input[type="number"]::-webkit-inner-spin-button,input[type="number"]::-webkit-outer-spin-button{height:auto}input[type="search"]{-webkit-appearance:textfield;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;box-sizing:content-box}input[type="search"]::-webkit-search-cancel-button,input[type="search"]::-webkit-search-decoration{-webkit-appearance:none}fieldset{border:1px solid #c0c0c0;margin:0 2px;padding:0.35em 0.625em 0.75em}legend{border:0;padding:0}textarea{overflow:auto}optgroup{font-weight:bold}table{border-collapse:collapse;border-spacing:0}td,th{padding:0}

這是我的CSS原始碼,壓縮了的。

(以下都是基於Chrome瀏覽器)

把這個檔案放在有些伺服器上去引用,完全正常。

但是我在阿里雲上買的空間,使用chrome載入這個css就超慢,看圖


居然用了2.2分鐘,這還要人活嗎?

而當我把引用換成我的另外一個網站(檔案是一模一樣)時,一切正常(我這個V5bjq網站也引用這個檔案,也一切正常)



有人說兩次的檔案大小都不一樣,遠端那個2.3kb,本地那個1.4kb,這我就不知道為嘛了,反正兩個檔案確實是一模一樣包括註釋都一樣,切都是壓縮在一行了的。

當我引用外域的這個檔案時候,沒有問題,說明可能是伺服器/空間什麼地方的問題。怎麼解決呢?

感覺問題可能是出在 css 程式碼內容上了,於是嘗試幾種方法修改了下,

只調換程式碼順序沒有用,
但修改任意引數值後加載就正常了,
或者中間或末尾加個空行也行

感覺應該並不是某個樣式導致的

所以最好也最簡單的方法就是在所有 css 程式碼末尾都空一行吧,也就是把壓縮版css檔案裡的"}"批量替換成"\}\n",或者使用其他工具直接格式化css檔案

這樣 Chrome 載入就正常了,對這種BUG實在無語