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網頁應用程式設計
120
|
第八章
接著,有人提出一種稱為 Comet 的進階資料傳輸技術。Commet 技術是由 iframexhr-
multipartHTML 檔案,以及長期輪詢(long polling)等技術結合而成。一旦啟用長期
輪詢機制,用戶端會開啟一組 XMLHttpRequestXHR)連線,如果伺服器端沒有新資
料需要傳給用戶端,這組連線就會一直保留著,讓用戶端和伺服器保持連繫狀態。伺服
器端只要一取得新資料,就會隨即透過這組連線將資料傳回給用戶端,並在用戶端收到
資料後馬上關閉連線。連線關閉後,整個流程又會再度重複。基本上,這種做法就能達
到讓伺服器主動推送資料的目的。
由於 Comet 技術尚未標準化,因此使用這項技術時需考慮到瀏覽器相容性的問題。除此
之外,還得考慮到程式效能的問題(因為伺服器端必須維護數組 HTTP 表頭)。我無意
貶低 Comet 這項技術—畢竟在過去沒有其他替代方案時,Comet 的確是一項可行的解決
方案。不過如果你很重視程式效能,就得審慎考慮是否適合採用這項技術。
一些瀏覽器的外掛程式(像 Adobe Flash Java)也能幫助伺服器主動推送資訊至用戶
端。這些外掛程式的做法是和伺服器之間建立低階的 TCP socket 連線,讓伺服器能主動
推送即時資訊至用戶端。不過得要特別注意一點:並非所有使用者都有安裝這些瀏覽器
外掛程式,而且很多企業的內部網路,會架設防火牆阻擋這些外掛程式的功能。
目前的 HTML5 規格裡面,已經有一些不錯的替代方案。只不過可能還得再等上一陣 ...
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