| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Server-Side Rendering for Angular
A minimal Angular starter for Universal JavaScript using TypeScript and Webpack
If you're looking for the Angular Universal repo go to angular/universal
This demo is built following the Angular-CLI Wiki guide
We're utilizing packages from the Angular Universal @nguniversal repo, such as ng-module-map-ngfactory-loader to enable Lazy Loading.
This repo demonstrates the use of 2 different forms of Server Side Rendering.
Prerender(prerender)
Server-Side Rendering(ssr)
npm run build:ssr && npm run serve:ssr - Compiles your application and spins up a Node Express to serve your Universal application on http://localhost:4000.
npm run build:prerender && npm run serve:prerender - Compiles your application and prerenders your applications files, spinning up a demo http-server so you can view it on http://localhost:8080 Note: To deploy your static site to a static hosting platform you will have to deploy the dist/browser folder, rather than the usual dist
When building Universal components in Angular there are a few things to keep in mind.
For the server bundle you may need to include your 3rd party module into nodeExternals whitelist
window, document, navigator, and other browser types - do not exist on the server - so using them, or any library that uses them (jQuery for example) will not work. You do have some options, if you truly need some of this functionality:
import { PLATFORM_ID } from '@angular/core';
import { isPlatformBrowser, isPlatformServer } from '@angular/common';
constructor(@Inject(PLATFORM_ID) private platformId: Object) { ... }
ngOnInit() {
if (isPlatformBrowser(this.platformId)) {
// Client only code.
...
}
if (isPlatformServer(this.platformId)) {
// Server only code.
...
}
}Don't manipulate the nativeElement directly. Use the Renderer2 from "@angular/core". We do this to ensure that in any environment we're able to change our view.
constructor(element: ElementRef, renderer: Renderer2) {
this.renderer.setStyle(element.nativeElement, 'font-size', 'x-large');
}| Back | FazBrowse Home | New Git URL |