search

Home  >  Q&A  >  body text

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?

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

为情所困为情所困2750 days ago1034

reply all(1)I'll reply

  • 滿天的星座

    滿天的星座2017-06-17 09:18:59

    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.

    reply
    0
  • Cancelreply