Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix (AoT - Lazy load) : lazy modules chunks creation on Server bundle #410

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

Merged
MarkPieszak merged 17 commits into TrilonIO:master from davidsekar:master
Sep 29, 2017
Merged

fix (AoT - Lazy load) : lazy modules chunks creation on Server bundle #410

MarkPieszak merged 17 commits into TrilonIO:master from davidsekar:master
Sep 29, 2017

Conversation

@davidsekar
Copy link
Contributor

@davidsekar davidsekar commented Sep 12, 2017

Commented code that prevented lazy modules chunks from getting created on PlatformServer.
This change worked fine in Dev. and Production build in my project with lazy loading feature.

davidsekar and others added 13 commits August 26, 2017 14:24
Pull latest changes from base fork
Merge latest changes from master repo
Pull changes from Base repo for preboot
Copy link
Contributor Author

Updated to latest npm packages (Webpack 3, aspnet prerendering 3 etc.,).

Added bundle analyzer to visualize & investigate the modules client/browser bundle

Copy link

naveedahmed1 commented Sep 16, 2017
edited
Loading

@davidsekar are you sure commenting out resolve: { mainFields: ['main'] }, is the way to ensure server size bundles are created properly with Lazy loading? What about module-map-ngfactory-loader see this angular/universal#741 (comment)

Copy link
Contributor Author

@naveedahmed1 You can see the comments provided in the same thread.

angular/universal#741 (comment)

there are many ways to solve this. One as you mentioned is replacing NgModuleFactoryLoader but if you're using webpack you can simply include angular into your webpack bundle which allows webpack to replace the System.import symbol.

naveedahmed1 reacted with thumbs up emoji

Copy link
Contributor Author

davidsekar commented Sep 16, 2017
edited
Loading

It works well with this PR, since we are using webpack... I can confirm that
lazy loaded routes are generated on ClientApp/dist as expected.

Further, refreshing the page from the lazy routes e.g., http://localhost:5000/lazy generates all the HTML/content on the server side without issues.

Copy link

And what about the bundle size? the main-server is ~13mb rite? Which is huge and will defiantly have performance issues when deployed on server especially in case of heavy traffic websites.

Copy link
Contributor Author

davidsekar commented Sep 16, 2017
edited
Loading

Server bundle is really a non-optimized pack of all required files
e.g.,

  1. It is not minified and has lot of comments
(function(e, a) { for(var i in a) e[i] = a[i]; }(exports, /******/ (function(modules) { // webpackBootstrap
/******/ 	// The module cache
/******/ 	var installedModules = {};
/******/
/******/ 	// object to store loaded chunks
/******/ 	// "0" means "already loaded"
/******/ 	var installedChunks = {
/******/ 		1: 0
/******/ 	};
/******/
/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {
....
/******/ 		};
  1. Based on this repo, a production server bundle has complete 'ngx-bootstrap', 'angular', 'bootstrap.css'. in non-minified state. So it is expected to appear huge where as, when compiled to native code by node- V8 engine (comments and spaces doesn't matter any more).

Size really does matter in the network transfers on the client/browser side.

  1. Server bundle has inline-source-maps enabled for source debugging.
    look for following base64 encoded sources (but this really doesn't affect the node script execution in any way, as they are are ignored)
    //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIndlYnBhY2s6Ly8vd2VicGFjay9ib290c3RyYXAgMDdlMjRlNmU3

Copy link
Member

This is great David thank you! Webpack 3.x and such were definitely much needed :)

I'll give this a test spin just to make sure it's all working!

Copy link

Thank you so much @davidsekar for the explanation. Can you please confirm if tree shaking is applied on the server bundle? Another thing, can we use @angular-devkit/build-optimizer to further optimize bundles both client and server side bundles? If we compare the size of the client side bundles generated through this repo with the bundles generated through Angular CLI, there is a huge difference, in my case bundles generated through Angular CLI are ~4 Mb whereas through this repo, the generated bundles for client side are over 7 mb.

Copy link
Contributor Author

davidsekar commented Sep 28, 2017
edited
Loading

@naveedahmed1
Size of the server bundle doesn't mean anything as it will be compiled to native code.

But as per the request, to avoid confusion I've enabled webpack.optimize.UglifyJsPlugin() on server bundle too. This has reduced the bundle size Server bundle size uglified

Copy link

naveedahmed1 commented Sep 28, 2017
edited
Loading

@davidsekar sounds great! One more that if it could be added. Currently the names of the files chunks doesn't contain any hash. Angular CLI automatically appends hash with file name to avoid any stale content caching issue. Can this be enabled for this repo as well?

Copy link
Contributor Author

Minifying server bundle broke preboot init(). still checking...

KhalipskiSiarhei reacted with confused emoji

Copy link

For me its working perfectly, I don't have ngx-bootstrap but material2 instead.

...ot script issue. Removed duplicated Bootstrap css from vendor bundle
Copy link
Contributor Author

davidsekar commented Sep 29, 2017
edited
Loading

  1. I have disabled mangling and compression (unsafe) for the server bundle, as it causes issue for preboot to create replay events scripts.
    Now the bundle size is approx 2.9 MB, but this is fine considering everything works as expected.

@naveedahmed1 : Preboot error will happen if you have the latest code from this repository, introduced in following PR
#401

  1. Duplicated Bootstrap css is now removed from the vendor bundle
    Bootstrap CSS duplicated #415

Copy link
Contributor Author

davidsekar commented Sep 29, 2017
edited
Loading

I've already implemented webpack config changes to add Hash values to lazy chunks in my project based on this repo (hashed names are only for production builds, as it caused issue with HMR in dev).

But I don't want those changes also to be bundled in this PR, as it causes issues for the repo maintainers to validate.

Copy link
Member

MarkPieszak commented Sep 29, 2017
edited
Loading

Can we merge this one in @davidsekar ? Sorry I've been away, unbelievably busy the past week+
TS 2.5 didn't cause any issues with 4.x?

Yeah good idea, I'll merge this in when you let me know we can do separate ones for any other great perf improvements!

Copy link

@davidsekar ssr in my project is also inspired from this repo (latest version) but I don't see any issue with compression. There must be some external library most probably bootstrap lib that would be breaking.

Copy link
Contributor Author

@naveedahmed1 When mangling or compression is ON, I see following error
preboot uglifyplugin issue

So I think it is bit more safe this way. Thanks for your feedback and time checking this PR :)

@MarkPieszak All features along with Signalr chat system is working fine.

I just see following warning, which is related to unresolved parameters that may become an error in Angular 5

Warning: Can't resolve all parameters for SignalR in D:/OSP/aspnetcore-angular2-universal-fork/node_modules/ng2
-signalr/src/services/signalr.d.ts:

@MarkPieszak MarkPieszak merged commit e627f3a into TrilonIO:master Sep 29, 2017
Copy link
Member

Excellent merged it for now, let's get latest and make sure everything works now just incase 🍻
Great work @davidsekar ! 👍

Copy link
Contributor

@davidsekar will this project not benefit from Webpack 3 scope hoisting?

https://medium.com/webpack/webpack-3-official-release-15fd2dd8f07b

I didn't see it in the webpack config.

module.exports = { 
 plugins: [
 new webpack.optimize.ModuleConcatenationPlugin()
 ]
};

Copy link

@davidsekar preboot doesn't work for me as well with enabled compress...

Copy link
Contributor Author

davidsekar commented Oct 3, 2017
edited
Loading

@KhalipskiSiarhei Please use the webpack config from master.

Unsafe Compression and mangling are disabled for main-server bundle to fix issue with preboot.
https://github.com/MarkPieszak/aspnetcore-angular2-universal/blob/ec03396a97aa6ff6f583678bca03057b369864a1/webpack.config.js#L83-L86

KhalipskiSiarhei reacted with thumbs up emoji

Copy link
Contributor Author

@jrmcdona
This PR was to fix the lazy load issue...

Yes, scope hoisting is awesome & should be incorporated through another PR

jrmcdona reacted with thumbs up emoji

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /