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網頁應用程式設計
模型(Model)和資料
|
47
資料清單中—這正是所謂的無限延伸捲軸模式(infinite scroll pattern)。總之,讓使用
者感受到的延遲越短越好。
切記,當系統在抓取新資料的同時,千萬不要讓系統的操作介面被鎖死。除了要在畫面
上呈現「資料載入中…」的提示訊息,還要讓操作介面維持可用的狀態。只有在極少
數的情況下,我們才會需要故意在載入資料時,讓畫面呈現無法讓使用者繼續操作的
狀態。
你可以在一開始載入網頁時,就把所有的資料都先安插在頁面某處,也可以另外發送一
些獨立的 HTTP 請求(像是透過 Ajax JSONP)動態載入資料。我個人比較建議採用
後面這種做法,因為一開始就把所有資料先安插在網頁裡,會讓網頁檔案變大,進而拖
慢下載網頁速度;透過一些並行的 HTTP 請求,能讓資料的載入速度快一些。此外,
AJAX JSON 還能讓你將 HTML 網頁儲存在快取區(cache),這樣就不用針對每次的
請求都重新動態產生一次網頁內容。
直接把資料放進網頁
我個人並不建議採用這種做法(原因已在前一段中提及),但在某些特定情況下,這種
做法還是會蠻有用的,特別是當我們需要載入非常少量的資料時。這種做法最大的好
處,就是非常容易實作。
採用這種做法,只需直接在網頁某處產生一組 JSON 物件就行了。假如是用 Ruby on
Rails,程式碼就會如下:
<script type="text/javascript">
var User = {};
User.records = <%= raw ...
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