angular / angular-cli

CLI tool for Angular
https://cli.angular.io
MIT License
26.72k stars 11.98k forks source link

feature request: single assets in i18n builds #26286

Open zip-fa opened 9 months ago

zip-fa commented 9 months ago

Command

build

Description

Hi. Currently angular just copy assets folder to every localized build. This leads to enormous dist size (in my case every locale with assets weigths 180MB, which can be multiplied by 15 locales).

Describe the solution you'd like

My proposal is to put assets folder in root directory, instead of copying it inside every built locale, and symlink it inside every locale. This will give us better build times, and also will fix issues where developers use absolute urls to assets, eg:

<img src=“/assets/img.png” />

My solution will give developers a way to use localized builds in mobile apps development (with capacitor for example; for now it’s strange to publish mobile app which weights over 2gb), better build times (no need to copy assets to every locale), better deploy times (transfer 180mb instead of 2.7GB)

Describe alternatives you've considered

Currently, the only issue i encounter, is absolute path usage (described it in my example with img src). I make symlink to get this working:

/en/assets -> /assets

zip-fa commented 9 months ago

A little update:

I just took two different localized builds and compared their hashTables from ngsw.json. Their assets' hashes are totally identical when using application builder, so i can assume, this feature can be done without pain.

zip-fa commented 8 months ago

Hi guys. I see “Needs discussion” badge was added, what does it mean? Will this be done?

alan-agius4 commented 8 months ago

needs: discussion means that this issue needs to be discussed further with the rest of the team.

We already discussed this during one of our team meetings but we haven't reached a definitive conclusion on the next steps. However, we reached a consensus that if an action is taken, it's improbable that it will involve a symlink-based approach.

dgp1130 commented 7 months ago

Spent some time discussing this in the team today. Our immediate reaction is that symlinks in the output might cause some issues for servers. In my experience, servers are typically hesitant to follow symlinks as they can often be the result of a misconfiguration issue and accidentally serve data which wasn't intended to be served. In this case, such symlinks would be internal to the served directory and (probably) safe, but I could see some servers getting this wrong or requiring explicitly enabling symlinks which server admins might not want to do.

An alternative proposal which might be better is to just emit an assets/ directory independently of the locale. That way there is only one copy of the assets. This has the additional benefit that there is only one URL for each asset. This way if a user downloads /assets/foo.png and then switches locale and re-requests /assets/foo.png, the URL is consistent and the browser cache can respond more quickly. This would also mean absolute paths can be used for requesting assets without having to manually include the locale.

This would definitely be a breaking change for existing applications, so I don't think we can automatically make this change, it would need to be behind a flag. Not sure what the naming for this flag would be, but under i18n options we could include something like singleAssetDir: true to enable this behavior. I do like this approach in general, and if it works out in practice we might want to consider enabling it by default for new applications, even if we don't necessarily have a path to automatically migrating existing apps.

zip-fa commented 7 months ago

This sounds like a good solution. I dont think there are many people who use i18n + ssr now, so it won’t break many apps. Maybe make this approach as default and add option like { cloneAssetsForEachLocale: boolean } (which is false by default)?

angular-robot[bot] commented 7 months ago

This feature request is now candidate for our backlog! In the next phase, the community has 60 days to upvote. If the request receives more than 20 upvotes, we'll move it to our consideration list.

You can find more details about the feature request process in our documentation.

demurgos commented 7 months ago

This feature would not only reduce build sizes considerably and improve caching, it also enables to output static files outside of the locale directories (favicon.ico, robots.txt, .well-known, etc.).

spock123 commented 7 months ago

I wish I could upvote this a million times. We have an application with a gazillion locales. For deployment we copy a local assets folder into the root folder of the dist folder, then recursively delete all the "locale" assets folders. But it's quite messy . Having a "non locale sensitive" assets would be really useful

angular-robot[bot] commented 6 months ago

Just a heads up that we kicked off a community voting process for your feature request. There are 20 days until the voting process ends.

Find more details about Angular's feature request process in our documentation.

angular-robot[bot] commented 5 months ago

Thank you for submitting your feature request! Looks like during the polling process it didn't collect a sufficient number of votes to move to the next stage.

We want to keep Angular rich and ergonomic and at the same time be mindful about its scope and learning journey. If you think your request could live outside Angular's scope, we'd encourage you to collaborate with the community on publishing it as an open source package.

You can find more details about the feature request process in our documentation.