-
Notifications
You must be signed in to change notification settings - Fork 124
fix: minimal guide for static assets #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
## Static assets | ||
|
||
## Recommended packages | ||
|
||
* [express-static](https://expressjs.com/en/starter/static-files.html). | ||
Express static is part of the express.js package that allows developers to expose static middlewares. | ||
|
||
## Guidance | ||
|
||
For serving static resources we recomend using `express.static` middleware as it has been widely used and tested in production. | ||
When using express.static() method, we can server static resources directly by specifying the folder name where we have stored our static resources. | ||
|
||
Documentation for the middleware can be found in: | ||
https://expressjs.com/en/starter/static-files.html | ||
|
||
### Caching | ||
|
||
The static middleware does server-side caching. | ||
It lets you do two methods of client-side caching: ETag and Max-Age | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add reference to https://developer.mozilla.org/en-US/docs/Web/HTTP/Caching There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cover only max-age - we need to change default argument. |
||
If you configured your static middleware to use client side caching please make sure that | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need that differentiated. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mention that ETag is not required. CacheControl only. ETAG - difference between usages. We need to dig deeper why not reliable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://www.freecodecamp.org/news/an-in-depth-introduction-to-http-caching-cache-control-vary/ reference for images and decision/sequence diagrams |
||
every modification in your code will be creating resources with different file name. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TODO for me to add section about middlelayers to server (nginx, apache, varnish, cdns, etc) |
||
When using bundlers you will explicitly need to generate different file names every time content changes. | ||
Example for webpack (most popular bundler) can be found here: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could mention if hash is used in filename, max age could be as long as a year. |
||
|
||
https://webpack.js.org/guides/caching |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additional guidance for why or why not to serve assets out of application
Serving assets out of application
Serving assets out of S3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@roastlechon knowing how much effort you have put I would not feel good to apply this change myself. I think it will be the best if you take this over and apply this change directly. Simply because this is exactly what we talked about and I would not say it better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i can pull your branch and create new PR if that would be okay by you. I can reference existing comments/feedback in the new PR, while you focus more on the other PRs (graphql)
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anything you will like. Really I haven't done much and amount of knowledge you have brought here is amazing. Feel free to create new PR, close this one - anything that will minimize hassle on your side