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網頁應用程式設計
96
|
第六章
包裝模組
截至目前為止,我們已經介紹完管理相依性和命名空間的實務做法,不過有個一開始提
過的問題還沒解決:該如何降低 HTTP 請求的數量。應用程式所有相依的模組,都必須
從遠端伺服器載入用戶端網頁,即使是用非同步的方式載入這些模組,仍然會對效能造
成嚴重的衝擊,減慢開啟應用程式的速度。
此外,我們還得將模組包裝成傳輸格式,雖然這麼做才能讓載入模組的程序以非同步方
式進行,但卻需要撰寫不少繁瑣的程式碼。有個做法可以一舉解決前述兩項問題:在伺
服器端將所有的模組合併成一個檔案。讓瀏覽器只需下載一個檔案,就可以載入所有必
需的模組,這種做法很明顯的有效率得多。而且現在的建置工具都非常聰明—它們不會
直接把多個模組粗魯的拼在一起,而會遞迴的分析出模組間的相依性關係,並且還會順
便把模組包裝成傳輸格式,讓你可以少寫一些程式。
很多模組建置工具,除了合併模組之外,還提供了自動精簡程式碼的功能,讓需要透過
網路傳輸的資料量變得更少。有些工具甚至還能直接和網頁伺服器整合,在第一次接
收載入模組請求時,自動化的對模組進行各種處理。例如:rack-modulr
https://github.
com/maccman/rack-modulr
)和 Transporter
http://github.com/kriszyp/transporter
)。
Rack
http://rack.rubyforge.org
)使用 rack-modulr 的範例如下:
require "rack/modulr"
use Rack::Modulr, ...
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