图像呈现在客户端还是服务器端? [英] Are Images Rendered Client Side or Server Side?

查看:36
本文介绍了图像呈现在客户端还是服务器端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始进行 Web 开发,尤其是 Reactjs,它引入了客户端渲染".我想我理解客户端与服务器端渲染的概念,但我不知道如何务实地理解这些概念.

I've just gotten started with web development, particularly Reactjs, which introduces "client side rendering." I think I understand the concept of client vs server side rendering, but I don't exactly know how to understand these concepts pragmatically.

例如,当我有 <img src="airplane.png"/> 时,这个图像是在客户端还是服务器端加载?IE,服务器是否将图像作为原始请求的一部分返回,还是在提供 HTML 后通过向服务器发出另一个请求从客户端加载图像?如果我要加载大量图片,我希望它们加载到客户端还是服务器端?

For example, when I have <img src="airplane.png" />, is this image being loaded client side or server side? IE, does the server return the image as part of the original request, or does the image get loaded from the client by making another request to the server after the HTML has been served? If I am loading a large amount of images, would I want them to be loaded client side or server side?

谢谢!

推荐答案

属于后一种情况.相应的标签将插入到 DOM页面,浏览器将向服务器(或托管图像的任何地方 - 它不必是您的服务器)再次请求该图像的内容.

It's the latter case. The respective tag will be inserted into the DOM of the page and the browser will make another request to the server (or to wherever the image is hosted - it doesn't have to be your server) for the contents of that image.

术语客户端与服务器端渲染是指计算文档结构的位置.在后者(和经典案例)中,服务器根据请求构建整个文档,而在前者中,它构建一个框架文档,并且由客户端的应用程序逻辑在应用程序运行时构建文档.当然,在服务器端渲染中,您有时也会开始修改 DOM 以制作交互式应用程序,因此描述没有那么清晰.

The term client-side vs server-side rendering refers to where the document structure is computed. In the latter (and classic case) the server builds a whole document as a result of the request, while in the former it builds a skeleton document and it's up to the application logic on the client side to construct the document as the application runs. Of course in server-side rendering, you'd at some point begin modifying the DOM as well in order to make interactive applications, so the delineation is not as clear cut as that.

可以提供图像作为data URL 将图像的内容作为 URL 嵌入,并将下载到初始文档请求的正文中.或者有时在附加的 CSS 文件中.但这对于不经常使用的小图像(svg 图标或类似的东西)很有用.

You can provide the image as a data URL which embeds the contents of the image as an URL, and which will be downloaded in the body of the initial document request. Or sometimes in an attached CSS file. But that's useful for small images which don't get used that often (svg icons or things like that).

这篇关于图像呈现在客户端还是服务器端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆