Skip to Content
JAVASCRIPT網頁應用程式設計
book

JAVASCRIPT網頁應用程式設計

by Alex MacCaw
January 2013
Intermediate to advanced
332 pages
5h 23m
Chinese
GoTop Information, Inc.
Content preview from JAVASCRIPT網頁應用程式設計
164
|
第十章
運用 CSS sprites 技術,能將多張圖檔合併成一張圖檔。如果想從圖檔裡面取出真正需要
用到的部分,只要用 CSS
background-image
background-position
屬性,設定好圖
檔儲存路徑和欲擷取的座標軸位置即可。
此外,避免不必要的轉址(redirect)也能有效降低 HTTP 請求數量。你或許會覺得,轉
址這種情況應該不常發生,但有一種很常見的情況:如果 URL 後面有一個斜線(
/
),
而你卻沒有輸入它,其實就會在你不知情的狀況下進行轉址。也就是說,輸入
http://
facebook.com
,會被轉址到
http://facebook.com/
。如果你用的網頁伺服器是 Apache,就能
透過 Alias mod_rewrite 來修正這個問題。
了解瀏覽器下載網頁資源的運作原理,也很重要。為了加快網頁產生的速度,大部分瀏
覽器都會採用並行機制,同時下載多個網頁需要用到的資源。不過,瀏覽器一定會等到
所有的 CSS JavaScript 檔案都下載完成,才能開始產生網頁。有些瀏覽器更誇張,會
在下載 JavaScript 檔案的同時,中斷所有其他資源的下載程序。
不過,大部分的 script 程式,都不會在網頁載入完成前,對 DOM 元件進行任何處理(像
是在 DOM 元件上新增事件處理器)。也就是說,其實瀏覽器並不需要等到所有東西都
下載完成之後,才開始產生網頁,也不需要為此犧牲效能。要解決這個問題,可以在
script 標籤上加個
defer ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

初めてのJavaScript 第3版 ―ES2015以降の最新ウェブ開発

初めてのJavaScript 第3版 ―ES2015以降の最新ウェブ開発

Ethan Brown, 武舎 広幸, 武舎 るみ
PHP编程:第4版

PHP编程:第4版

Kevin Tatroe, Peter MacIntyre
Strange Code

Strange Code

Ronald T. Kneusel
Perfecting Your Thinking Skills

Perfecting Your Thinking Skills

MIT Sloan Management Review

Publisher Resources

ISBN: 9789862766811