Asker
Asker

Reputation: 1685

What do "static" and "non-static" mean in the context of Express?

The documentation for Express's express.static() middleware states:

To serve static files such as images, CSS files, and JavaScript files, use the express.static built-in middleware function in Express.

It seems that the JS files for dynamic React apps are included, since express.static("some_build_dir") seems to work even when some_build_dir is a front-end React app.

However, it seems natural that React apps which use JS to dynamically generate web content should be considered dynamic, rather than static, so there's something I'm missing here.

Q: What kinds of things does Express actually consider "non-static" or "dynamic", then, if even the source files of React apps do not qualify?

Upvotes: 2

Views: 1625

Answers (2)

Abanoub Istfanous
Abanoub Istfanous

Reputation: 966

static middleware means it is a static file or folders, and it is a true. the react app is static, the code not changed, the same index.html will serve to user as static file then the content will changed with user interactions and api requests but still the source of files the same and not changed

Upvotes: 0

Quentin
Quentin

Reputation: 943561

Static: Files that the web server (Express) reads from the file system and sends, unmodified, to the client.

Non-static: Responses that are programmatically generated (e.g. from a template with data from a database being inserted into it).


However, it seems natural that React apps which use JS to dynamically generate web content should be considered dynamic, rather than static, so there's something I'm missing here.

As far as the server is concerned, the JS source code and bootstrap HTML file that it sends to the client are static. The dynamic part of them is handled client-side which is outside the server's control.

Upvotes: 2

Related Questions