javascript - In html, images, JS, and CSS obtain resources on the server through the src or url of the tag. Does the server need to write a corresponding response for each resource?
为情所困
为情所困 2017-06-17 09:16:59
0
1
1010

Recently Xiaobai is learning nodeJS, and when he was doing network programming, he thought that the browser first sends an HTTP request to a page through the entered address (the server returns an HTML file in response to the request), and then the pictures, JS, CSS obtains resources on the server through the src or href of the tag (the browser also issues an http request), but there are so many pictures in HTML, it is impossible to write a separate response on the server side for each one, right? Does that mean the server writes a generic response and sends the corresponding resource by matching the request address? Or should we put the resource on the server without processing it and obtain it automatically as long as the address is correct? Hope to get some advice, thank you

为情所困
为情所困

reply all(1)
滿天的星座

The server writes a generic response and sends the corresponding resource by matching the request address

This is correct. Of course, during the development process, libraries are generally used. For example, express has the app.use(express.static('public')) method, and koa has koa-static middleware.

Put the resources to the server without processing them. As long as the address is correct, they will be automatically obtained

This is also correct, but it requires some tools, such as nginx.
When the node server program is behind nginx, you can use nginx to proxy these static resources.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template