GithubHelp home page GithubHelp logo

rainstormza / universal Goto Github PK

View Code? Open in Web Editor NEW

This project forked from angular/universal

0.0 1.0 0.0 4.04 MB

Universal javascript support for Angular

License: MIT License

Shell 3.92% TypeScript 96.08%

universal's Introduction

Current Status: Universal platform API has been merged into Angular 4.0!

(The code for the 2.x version of angular2-universal has been archived at https://github.com/angular/universal/tree/2.x)

Build Status Join the chat at https://gitter.im/angular/universal

Angular Universal

Universal (isomorphic) JavaScript support for Angular.

Table of Contents


Introduction

The Angular Universal project consists of the base platform API and the surrounding tools that enables developer to do server side rendering(or pre-rendering) of Angular applications. The platform API part has been merged into Angular core as of 4.0.

This repository will host the various tools like engines to integrate with various backends(NodeJS, ASP.NET etc.) and also extra modules and examples to help you started with server side rendering.

Upgrading from Angular2-Universal

If you're coming from the original angular2-universal (2.x) here are some helpful steps for porting your application to Angular 4 & platform-server.

Go here to find the guide


Roadmap

Angular 4.0

  • Integrate the platform API into core (Done)
  • Support Title and Meta services on the server (Done)
  • Write documentation for core API (In Progress)
  • Develop Express, ASP.NET Core, Hapi engines (In Progress)

Angular 4.1+

  • Hooks in renderModule* to do stuff just before rendering to string
  • Generic state transfer API in the platform
  • Http Transfer State Module that uses HTTP interceptors and state transfer API
  • Better internal performance and stress tests
  • Make it easier to write unit tests for Universal components
  • Support AppShell use cases
  • Unified Document Service that combines Meta and Title services and adds more features
  • Angular CLI support for Universal
  • Material 2 works on Universal
  • Provide a solution for Java backends

Angular 5.0 and Beyond

  • Full client rehydration strategy that reuses DOM elements/CSS rendered on the server
  • Make it easier to support other 3rd part libraries like jQuery/d3 that aren't Universal aware
  • Node.js bridge protocol to communicate with different language backends - Django, Go, PHP etc.

Getting Started

* NodeJS :: Example repo

  • Minimal webpack & universal example with Angular 4.0

* ASP.NET Core :: Universal Starter repo

  • Installation: Clone the above repo, npm i && dotnet restore (VStudio will run these automatically when opening the project)
  • Launch files included for both VSCode & VStudio to run/debug automatically (press F5).

Universal "Gotchas"

When building Universal components in Angular 2 there are a few things to keep in mind.

  • 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:

    • If you need to use them, consider limiting them to only your client and wrapping them situationally. You can use the Object injected using the PLATFORM_ID token to check whether the current platform is browser or server.
     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.
         ...
       }
     }
    
    • Try to limit or avoid using setTimeout. It will slow down the server-side rendering process. Make sure to remove them in the ngOnDestroy method of your Components.
    • Also for RxJs timeouts, make sure to cancel their stream on success, for they can slow down rendering as well.
  • Don't manipulate the nativeElement directly. Use the Renderer2. We do this to ensure that in any environment we're able to change our view.

constructor(element: ElementRef, renderer: Renderer) {
  renderer.setElementStyle(element.nativeElement, 'font-size', 'x-large');
}
  • The application runs XHR requests on the server & once again on the Client-side (when the application bootstraps)
    • Use a cache that's transferred from server to client (TODO: Point to the example)
  • Know the difference between attributes and properties in relation to the DOM.
  • Keep your directives stateless as much as possible. For stateful directives, you may need to provide an attribute that reflects the corresponding property with an initial string value such as url in img tag. For our native element the src attribute is reflected as the src property of the element type HTMLImageElement.

Preboot

Control server-rendered page and transfer state before client-side web app loads to the client-side-app. Repo

What's in a name?

We believe that using the word "universal" is correct when referring to a JavaScript Application that runs in more environments than the browser. (inspired by Universal JavaScript)

Universal Team

The Universal project is driven by community contributions. Please send us your Pull Requests!

License

MIT License

universal's People

Contributors

patrickjs avatar markpieszak avatar jeffwhelpley avatar manekinekko avatar jeffbcross avatar ashsidhu avatar wesleycho avatar vikerman avatar frozenpandaz avatar dbabaioff avatar vvakame avatar tamascsaba avatar johngorter avatar steve8708 avatar laskoviymishka avatar playground avatar valorkin avatar notvitaliy avatar nathanwalker avatar vangorden avatar quinntynebrown avatar krijger avatar gitter-badger avatar tbosch avatar wwelling avatar somethiiing avatar alfamegaxq avatar ca136 avatar dietergoetelen avatar lightningtgc avatar

Watchers

Supakorn Thongtra avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.