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
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.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.