-
Notifications
You must be signed in to change notification settings - Fork 27.2k
Make BrowserAnimationsModule delay-loadable #38982
Copy link
Copy link
Closed
Labels
area: animationslegacy animations package only. Otherwise use area: core.legacy animations package only. Otherwise use area: core.featureLabel used to distinguish feature request from other issuesLabel used to distinguish feature request from other issuesfeature: in backlogFeature request for which voting has completed and is now in the backlogFeature request for which voting has completed and is now in the backlogfeature: under considerationFeature request for which voting has completed and the request is now under considerationFeature request for which voting has completed and the request is now under considerationneeds: discussionIndicates than an issue is an open discussionIndicates than an issue is an open discussion
Milestone
Metadata
Metadata
Assignees
Labels
area: animationslegacy animations package only. Otherwise use area: core.legacy animations package only. Otherwise use area: core.featureLabel used to distinguish feature request from other issuesLabel used to distinguish feature request from other issuesfeature: in backlogFeature request for which voting has completed and is now in the backlogFeature request for which voting has completed and is now in the backlogfeature: under considerationFeature request for which voting has completed and the request is now under considerationFeature request for which voting has completed and the request is now under considerationneeds: discussionIndicates than an issue is an open discussionIndicates than an issue is an open discussion
🚀 feature request
Relevant Package
This feature request is for @angular/platform-browser/animations
Description
To make our app start as quickly as possible, particularly on mobile, I've done a bunch of work to minimize initial bundle size. One of the approaches I'm using is async imports (eg
import('../foo/foo.module').then(m => m.FooModule)) shortly after the app is loaded, for logic that isn't absolutely required for initial load + first render.While we use angular animations extensively (because it's awesome!), we don't need it for first page view (relying on CSS animations for the first few seconds). It is currently not possible to move the
BrowserAnimationsModuleimport to a different module from whereBrowserModuleis imported - becauseBrowserAnimationModuleexportsBrowserModule, and theBrowserModuleconstructor requires thatBrowserModulehasn't been loaded in a parent injector. Also, angular won't start ifBrowserModuleisn't imported by the root module.I would like the ability to delay load
BrowserAnimationsModule, and I think this would be a useful ability for anyone working to speed initial load.The easiest repro is to create a new project using
ng new --strict --minimal. Next,ng build --prodgives me a main bundle size of 187kB.If I'm going to use @angular/animations in my app, I am currently required to import
BrowserAnimationsModulein the root module:Just doing this increases the main bundle to
258 kB(+71kB or +38%).Describe the solution you'd like
I'd like to be able to initialize the BrowserAnimationsModule shortly after app load, and have animations work after that point:
await delay(1000); import('@angular/platform-browser/animations').then(m => m.BrowserAnimationsModule );This will probably require that the
BrowserAnimationsModuleno longer re-exportBrowserModule.Describe alternatives you've considered
The current required configuration works, it just adds unnecessary size to the initial bundle.
I did try directly importing
BROWSER_ANIMATIONS_PROVIDERS(which would get around theBrowserModulere-import check), but I couldn't access them.Another alternative would be to fork the angular code and try to create a new version of BrowserAnimationsModule that doesn't have these limitations, but I haven't gotten desparate enough for that. We'll see what the Angular team thinks about this proposal.