Skip to content
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

Add static asset caching #615

Closed

Conversation

alexnewmannn
Copy link

Recently we have demoed our prototype on heroku and locally through presentations and video, the prototype doesn't cache any static assets so during these presentations theres often a flash of unstyled text and layout shifting due to the lack of CSS and webfonts.

This PR will allow a cache maxAge option to be set through config or environment variables, which will default to 0 if neither is set (should make it less of a breaking change as it won't be required in config)

Copy link
Contributor

@NickColley NickColley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me Alex.

We need to document this change in the CHANGELOG: https://github.com/alphagov/govuk-prototype-kit/blob/master/CHANGELOG.md

I can do this for you if you want.

This kind of work makes me think that we could have a 'development mode' and a 'production mode' (something to indicate this is being put in front of a user), which would set these kinds of defaults for you.

@alexnewmannn
Copy link
Author

Thanks, I can add it in no worries, I need to squash commits anyway and make a change @colinrotherham suggested 👍
Yeh I agree, even something simple like minifying all assets and making them cache-bustable (not sure thats a word). Might be worth adding an issue for discussion of what people think could be beneficial to include in such a mode?

useBrowserSync: 'true',

// Set a value (in milliseconds) for the max age of all static assets in cache
assetsMaxAge: 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all looks great, thanks, but I wonder if we can make the content and variable name here clearer, will have a think.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeh definitely, the name here and names in server are bothering me a bit, maxAge is too vague but I'm not sure we are there yet.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed on Slack, it might be a more consistent approach to have useCache, with that only happening in production. Or not have a config at all and just cache on production.

Copy link
Contributor

@joelanman joelanman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we should add caching without also adding cache busting. Otherwise users will not be able to deploy changes and have those changes update for their users within the cache time.

@alexnewmannn
Copy link
Author

@joelanman Yeh i'll take a look at that as well, it may be worth it there's definitely ways around it such as manually appending a query string to the relevant assets before deploying, but it's far from ideal.

@kr8n3r kr8n3r force-pushed the add-static-asset-caching branch from ad594f9 to 2a1af5c Compare October 29, 2018 15:40
@joelanman
Copy link
Contributor

closing in favour of #627 which adds cache busting

@joelanman joelanman closed this Nov 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants