单独的图像服务器(例如images.mydomain.com)的优点和缺点?
我们有一些图像和 PDF 文档,可以通过我们的网站获取。 这些图像和文档存储在源代码管理中,并在部署时复制内容。 我们正在考虑创建一个单独的图像服务器来放置我们的库存图像和 PDF 文档 - 从而显着减少我们的部署包的体积。
有人有这种方法的经验吗?
我想知道是否存在任何“陷阱” - 例如 XSS 问题和/或从备用子域传递内容的浏览器问题?
We have several images and PDF documents that are available via our website. These images and documents are stored in source control and are copied content on deployment. We are considering creating a separate image server to put our stock images and PDF docs on - thus significantly decreasing the bulk of our deployment package.
Does anyone have experience with this approach?
I am wondering about any "gotchas" - like XSS issues and/or browser issues delivering content from the alternate sub-domain?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
优点:
许多浏览器只会分配两个套接字来从单个主机下载资源。 因此,如果从 www.domain.com 下载 index.html 并且它引用了 6 个图像文件、3 个 javascript 文件和 3 个 CSS 文件(全部在 www.domain.com 上),则浏览器将一次下载 2 个文件,其中其他阻塞直到套接字空闲。
如果您将 6 个图像文件拉到单独的主机(例如 images.domain.com)上,您将获得额外的两个专用于下载图像的套接字。 这会并行化资源下载过程,因此从理论上讲,您的页面渲染速度可以提高两倍。
缺点:
如果您使用 SSL,则需要获取 images.domain.com 的附加单主机 SSL 证书或 *.domain.com 的通配符 SSL 证书(与任何子域匹配)。 如果不这样做,将会在浏览器中生成一条警告,指出该页面包含混合的安全和不安全内容。
Pro:
Many browsers will only allocate two sockets to downloading assets from a single host. So if index.html is downloaded from www.domain.com and it references 6 image files, 3 javascript files, and 3 CSS files (all on www.domain.com), the browser will download them 2 at a time, with the other blocking until a socket is free.
If you pull the 6 image files off onto a separate host, say images.domain.com, you get an extra two sockets dedicated to download your images. This parallelizes the asset download process so, in theory, your page could render twice as fast.
Con:
If you're using SSL, you would need to either get an additional single-host SSL certificate for images.domain.com or a wildcard SSL certificate for *.domain.com (matches any subdomain). Failure to do so will generate a warning in the browser saying the page contains mixed secure and insecure content.
对于不同的域,您也不会在每次请求时都发送 cookie 数据。 这可以提高性能。
You will also, with a different domain, not send the cookies data with every request. This can increase performance.
另一件尚未提及的事情是,您可以使用不同的 Web 服务器来提供不同类型的内容。 例如,您的静态内容可以通过 lighttpd 或 nginx 提供,同时仍然通过 Apache 提供动态内容。
Another thing not yet mentioned is that you can use different web servers to serve different sorts of content. For example, your static content could be served via lighttpd or nginx while still serving your dynamic content off Apache.
优点:
- 负载平衡
- 隔离不同的功能
缺点:
- 更多工作(当您在主站点上创建页面时,您必须维护单独服务器上的资源)
像 XSS 这样的问题是代码未清理输入的问题(或就此而言的输出)。 唯一可能出现的问题是,如果您有用于身份验证的子域特定 cookie。但这确实是一个微不足道的修复。
Pros:
-load balancing
-isolating a different functionality
Cons:
-more work (when you create a page on the main site you would have to maintain the resources on the separate server)
Things like XSS is a problem of code not sanitizing input (or output for that matter). The only issue that could arise is if you have sub-domain specific cookies that are used for authentication.. but that's really a trivial fix.
如果您提供 HTTPS 服务并且提供来自 HTTP 域的图像,那么您在使用它时会弹出浏览器安全警报警告。
因此,如果您使用 HTTPS,如果您不想惹恼您的用户,则需要为您的图像域购买 HTTPS :)
还有其他方法可以解决此问题,但它不是特别在本讨论的范围内回答 - 这只是一个警告!
If you're serving HTTPS and you serve an image from an HTTP domain then you'll get browser security alert warnings pop up when you use it.
So if you do HTTPS, you'll need to buy HTTPS for your image domain awell if you don't want to annoy the hell out of your users :)
There are other ways around this, but it's not particularly in the scope of this answer - it was just a warning!