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版)
静态内容
|
193
17.6
 小结
即便是像静态资源这样看起来很简单的东西,也可能带来很多的麻烦。然而,静态资源几
乎代表着实际给用户传输的数据块,因此花一些时间来优化它们,收益将相当可观。
还有一个前面没有提到的可行的静态资源方案是,一开始就把它们托管到
CDN
上
,并且
在你的视图和
CSS
中始终使用资源的完整
URL
路径
。这样做的好处是简单,但如果你周
末想去参加一个在没有互联网连接的林中小屋举办的“黑客马拉松”,那可就麻烦了。
如果精细的资源打包和文件最小化工作对你的应用来说并不值得,则可以简化它们,以
便节省一些时间。尤其是如果网站只包含一两个
JavaScript
文
件,而所有的
CSS
都在一
个文件里,则很可能就会完全跳过打包这一步。不过真实世界的应用都有随着时间而增
长的趋势。
不管选择什么技术来提供静态资源,我都强烈建议把它们跟动态资源分离开,最好是托管
到
CDN
上
。如果你觉得这样很麻烦,那我可以向你保证它远没有听起来那么难,尤其是
如果在部署系统上花上一点儿时间,就会发现把静态资源部署到一个位置,把应用部署到
另一个位置,整个过程都是自动化的。
如果担心托管到
CDN
上的成本
,建议先看看目前的托管费用。大部分的托管服务提供商
按带宽收费,即使你并不知道这条计费规则。然而,如果突然间网站被
Slashdot
提到了
,
可能就会收到意料之外的托管服务的账单。
CDN
服务通常是按用多少付多少来设置的
。下
面这个例子可作为参考:我曾经为一个中等规模的地区性公司管理一个网站,这个网站每
个月使用
20GB
的流量
,而花在托管静态资源上的费用只有几美元(它是一个偏重多媒体 ...
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