Skip to Content
Node与Express开发(第2版)
book

Node与Express开发(第2版)

by Ethan Brown
June 2021
Intermediate to advanced
290 pages
9h 21m
Chinese
Posts & Telecom Press
Content preview from Node与Express开发(第2版)
静态内容
|
189
17.2
 内容分发网络
(
CDN
)
当你要把网站推上生产的时候,网站的静态资源必须存放于互联网上的
某个地方
。你也许
习惯于把它们存放在生成所有动态
HTML
的同一台服务器上
,目前为止我们的示例应用也
是这么做的:使用
node meadowlark.js
运行起来的
Node/Express
服务器,除了提供
HTML
服务之外,还提供静态资源服务。不过,如果你想最大化网站的性能(或者希望在将来能
够做到),就会希望把静态资源托管到一个
CDN
上。
CDN
就是把分发静态资源优化到极
致的服务器。它通过专门的响应头(一会儿就会学习)启用了浏览器缓存。
CDN
也可以启用
基于地理位置的优化
(常称为
边缘缓存
),也就是说,
CDN
可以先找出地
理上距当前客户端最近的一台服务器,然后从这台服务器发送静态内容。虽然互联网传输
数据很快(虽不是以光速运行,但也很接近),但是传输
100
英里还是比
1000
英里速度要
快。虽然单次节省的时间或许很少,但如果考虑到用户数、请求数、资源数,累积起来就
显得快了。
大多数静态资源是在
HTML
视图中引用的
(通过
<link>
标签引用
CSS
文件、
<script>
引用
JavaScript
文件、
<img>
引用图片文件,再加上多媒体嵌入标签)。
CSS
文件中包
含静态引用也是很常见的,比如通常使用的
background-image
属性。最后,有时候在
JavaScript
中也会引用静态资源
,比如有的
JavaScript
代码会动态地修改或插入
<img>
标签
或
background-image
属性。
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

面向对象的思考过程(原书第5版)

面向对象的思考过程(原书第5版)

马特 魏斯费尔德
精通模块化JavaScript

精通模块化JavaScript

Nicolás Bevacqua

Publisher Resources

ISBN: 9787115565099