-
Notifications
You must be signed in to change notification settings - Fork 12k
image assets cache purge question #3959
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
Comments
There's something in master not yet released. A new flag for I suspect you can try setting it to P.S. Reference: #3885 |
ng build --env=prod --output-hashing=all The entire directory is copied into the build folder. According to the build tests https://github.com/angular/angular-cli/blob/master/tests/e2e/tests/build/output-hashing.ts export default function() { The defect needs to be reopened. |
Assets are intended to be copied verbatim with no additional processing. That is their defining characteristic. |
are the files mentioned as assets in angular-cli.json I18n contains 2 files
I am using them for translations. These files are cached. As per the documention
must add hashing to all files, irrespective of contents in assets. |
My team ended up appending a timestamp of the release onto our assets, eg. @clydin If assets were intentionally not hashed, what is the suggested approach for invalidating cache of assets? |
@clydin I would also love to know what the recommended practice is for this |
Please see the following for recommended practices. Note that server configuration is a critical element to an effective caching strategy. |
Thanks for the article @clydin. I totally agree that correct cache configuration on the server is important for ensuring browsers treat cached assets correctly. However, a common strategy to ensure the browser immediately requests a new version when an asset has changed is to use unique names for assets based on their contents. The article you linked specifically calls this out:
With the behaviour of angular just copying the assets with no processing, no hash is generated for these assets, making it not possible to achieve this, and it was this I was hoping you had advice on. |
@jeffora Further in that same section, the example specifically using an image (as a token asset example) without a unique hash in the file name. |
Sure, for a photo that rarely or never changes, where the user experience will not change with an out of date image. However, if the asset is an SVG for a menu item, or something that should be considered part of a single "deployment", there is no way to make sure a new version of the app will reference the latest version of the asset. Another issue is that as assets are not processed at all, they do not follow the |
In that case, you have several options. Three of which are to either set the image to no-cache (like the index) and ensure Etags are being used; with HTTP/2 there is no reconnection overhead. Or if the SVG is small, inline it in the template HTML. Or use a CSS background image; which has numerous advantages over an HTML img element (e.g., transformations, animations, etc.). As to the second aspect, base HREF would be the preferred option in that scenario. There is rarely a reason to use deploy URL over base HREF. |
Ok thanks for the discussion. It sounds like there is no out of the box support via the angular cli, so I'll look into 6+ builder pack options to customise it ourselves. Base href is not really appropriate for this use case, as that tells the browser that all relative URLs on the page should be interpreted as relative to the base href, which is not the behaviour we're after. We serve the site (index.html) from one domain, e.g. The other options suggested might work for specific cases, but they all feel like workarounds - surely there is a valid (and possibly common) use case where static assets that are not JS / CSS should be processed through the same content pipeline as JS / CSS. This is fully supported by webpack, so it would be nice to have an easy way to opt in to this functionality in angular. |
With HTTP/2’s header compression, the entire cookie can be encoded in 1 to 2 bytes for repeat requests. There’s no need for a complex setup if cookie request elimination is the primary goal. |
I really thought that an absolutely amazing framework like angular would take care of such a basic thing. A bit disappointing to see that assets are not hashed to prevent them from being stuck on cache... but I hope to see this improvement some time. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Hi there,
I noticed that all assets are copied over to the dist directory. However even if we change the image in src/assets directory. The image wont be pulled in after release as name is the same.
It would be nice if during a release we update urls in css/html simply appending version number of sort in css such as:
url(assets/logo.png) -> url(assets/logo.png?123)
this would force the browser to download new image. Is this something we can do with cli ?
Thanks for the help
The text was updated successfully, but these errors were encountered: