λΈλ‘ν°λ·λ· κΈ°μ¬μ λ°λ₯΄λ©΄ 2017λ λνλ―Όκ΅ 1λΆκΈ° νκ· λͺ¨λ°μΌ μΈν°λ· μλλ 28Mbpsμ λλ€. μ΄ μλλ‘ κ³μ°λ [email protected]μ λ€μ΄λ‘λ μκ°μ 8.5ms(μλ κ³μ°μ μ°Έκ³ )μ λλ€. μ¬κΈ°μ LTEλ§ νκ· μλ΅μλ 30ms, λ€μ΄λ°μ μ€ν¬λ¦½νΈλ₯Ό νμ±νκ³ μ€ννλ λ° κΉμ§ 15ms(iPhone 5S κΈ°μ€)λ₯Ό λνλ©΄ λλ΅ 53.5msμ λλ€. μκ°μ΄ μ§λ μλ£λ₯Ό ν λλ‘ κ³μ°ν κ²°κ³Όμ΄μ§λ§. μ΄λ§μ λ νκ· μ΄κ±°λ μ’μ 쑰건μΌλ κΈ°μ€μ΄κ³ . λ³΄ν΅ μ΄λ° νμΌμ νλλ§ λ€μ΄λ‘λνλκ²μ΄ μλκΈ° λλ¬Έμ μ€μ μλΉμ€λ₯Ό μ¬μ©ν λλ λ λ릴 κ²μ λλ€.
30KB after gzipped.
28Mbps = 3500KBps
1s : 3500KB = x : 30KB
x = 0.008571429
μλΉμ€ μ΄κΈ° μ§μ
μκ°μ μ€μμ±μ κ·λͺ¨κ° 컀μ§μλ‘ μ€μν΄μ§λλ€. Googleμ 10κ°μ κ²μκ²°κ³Όλ₯Ό 400msμ λ
ΈμΆνλ κ²μμ. 30κ°μ κ²μκ²°κ³Όλ₯Ό 900msμ λ
ΈμΆνλλ‘ λ³κ²½ν ν 20%μ νΈλν½κ³Ό κ΄κ³ μμ΅ κ°μλ₯Ό κ²ͺμλ€κ³ ν©λλ€. Google Mapsλ 리μμ€ μ©λμ 30KB μ€μΈ κ²μΌλ‘ 첫주 10%μ νΈλν½ μ¦κ°λ₯Ό. μ΄ν 3μ£Ό λ΄μ μΆκ°λ‘ 25%μ νΈλν½μ΄ μ¦κ°νλ€κ³ ν©λλ€. Amazon.comμ λ‘λ νμμ΄ 100msμ¦κ°ν λλ§λ€ λ§€μΆμ‘μ΄ 1%μ© κ°μνλ€κ³ ν©λλ€. λ³Έλ¬Έ λ§ν¬
μμ λ΄μ©μ λ³Ό λ 30msλ κ²°μ½ μλ€κ³ ν μ μμ΅λλ€. μλΉμ€ μ΄κΈ° μ§μ μκ°μ μ€μΌ μ μλ λ°©λ²μ λ§μ§λ§ μ΄ κΈμμ μκ°ν λμ λͺ¨λ λ‘λ©μ κ°μ₯ κ°νΈνλ©΄μλ ν° ν¨κ³Όλ₯Ό λ³Ό μ μλ κΈ°λ²μ λλ€. Angularλ μΆμλ λλΆν° μ΄ κΈ°λ₯μ κ°μ§κ³ μμμ΅λλ€. λμ μΌλ‘ λ°μ 리μμ€λ€μ λͺ¨μ λ³λμ λͺ¨λλ‘ λ§λ€κ³ μλ μ½λμ κ°μ΄ λΌμ°ν°μ λ±λ‘νλ©΄ λ©λλ€.
const routes: Routes = [{
path: 'customers',
loadChildren: 'app/customers/customers.module#CustomersModule'
}];
μ¬μ©μκ° /customersμ μ μνλ©΄ μλμΌλ‘ app-customers-customers.module.jsνμΌμ λμ μΌλ‘ λ€μ΄λ‘λλ°κ³ νμΌ λ΄ CustomerModuleμ μ¬μ©ν μ μκ² λ©λλ€. jQueryλ±μ λΌμ΄λΈλ¬λ¦¬λ₯Ό ν΄λΉ νμ΄μ§μμλ§ μ¬μ©νλ κ²μ΄ νμ€νλ€λ©΄. μ΄ λΆλ¦¬λ λͺ¨λμμ μ¬μ©νλκ²μΌλ‘ κ°λ¨ν κΈ°λ²μ μ μ©ν μ μμ΅λλ€. μ΄λ κ² λΆλ¦¬λ λͺ¨λ νμΌμ μ©λ λ§νΌ μλΉμ€ μ΄κΈ° μ§μ
μ 걸리λ μκ°μ μ€μΌ μ μμ΅λλ€.
νμ§λ§ μ΄λ€ λͺ¨λμ ν΄λΉ μ»΄ν¬λνΈκ° μ¬μ©λλ μμ μ λ°λ κ²μ΄ λ μμ°μ€λ½κ³ νΈλ¦¬ν κ²½μ°κ° μμ΅λλ€. μμ§μ μλν°λ₯Ό μλ‘ λ€ μ μμ΅λλ€. λμ λͺ¨λ λ‘λ© μμ΄ κ°λ°λ Aνμ΄μ§μ μμ§μ μλν°λ₯Ό μΆκ°νλ€κ³ κ°μ ν΄ λ΄ μλ€. λΌμ°ν°μ κΈ°μ‘΄μ λ±λ‘λ μ»΄ν¬λνΈλ₯Ό λͺ¨λλ‘ λ³κ²½νκ³ μμ κ°μ΄ μμ ν΄μΌ ν©λλ€. λ μ΄λ κ² λͺ¨λμ λμ μΌλ‘ λ°λλ€κ³ ν΄λ. λ§μ½ μμ§μ μλν° μ체λ₯Ό νΉμ λ²νΌμΌλ‘ λ ΈμΆνλλ‘ κΈ°νν κ²½μ° μ€μ μμ§μ μλν°λ₯Ό μ¬μ©νμ§ μμλ νμ΄μ§ μ§μ λ§μΌλ‘ 리μμ€λ₯Ό λ°κ² λ©λλ€.
μμ§μ
μλν° μ»΄ν¬λνΈλ₯Ό μ€μ λ‘ μ¬μ©νλ μμ μ κ΄λ ¨ λͺ¨λμ λ€μ΄λ‘λλ°λλ‘ νκ³ μΆμΌλ©΄ NgModuleFactoryLoaderλ₯Ό μ¬μ©νλ©΄ λ©λλ€. μ΄ λͺ¨λμ μ¬μ©νκΈ° μν΄μλ λ¨Όμ λ£¨νΈ λͺ¨λμ ν΄λΉ λͺ¨λλ€μ μΆκ°ν΄μΌ ν©λλ€.
@NgModule({
...
providers: [{provide: NgModuleFactoryLoader, useClass: SystemJsNgModuleLoader}]
})
export class AppModule {}
κ·Έλ¦¬κ³ νμν 리μμ€λ€μ λμ μΌλ‘ λ‘λνλ λ³λμ λͺ¨λμ λ§λλλ€.
@NgModule()
export class EditorModule {
constructor(@Inject(DOCUMENT) private document: Document) {}
async load() {
const style = document.createElement('style');
style.textContent = require('../../assets/css/editor.css').default;
this.document.head.appendChild(style);
return require('../../assets/js/editor.js');
}
}
λμ μΌλ‘ λ€μ΄λ‘λν λͺ¨λμ μ§μ μ¬μ©νμ§ μμλ λ κ²½μ° μ½λλ₯Ό μμ±μμ ꡬννλ©΄ λ©λλ€. μμ μ½λμμλ editor.jsνμΌμ΄ λ΄λ³΄λ΄λ ν¨μλ₯Ό μ§μ μ¬μ©ν΄μΌ νκΈ° λλ¬Έμ ν΄λΉ λͺ¨λμ λ°ννλ λ³λμ λ©μλ loadμ ꡬνν©λλ€. λͺ¨λμ ꡬννμΌλ©΄ angular.json νμΌμ ν΄λΉ λͺ¨λμ λ±λ‘ν©λλ€.
{
"projects": {
"my-app": {
"architect": {
"build": {
"lazyModules": [
"src/app/modules/editor.module#EditorModule"
]
}
}
}
}
}
lazyModulesμ λ°°μ΄μ ν΄λΉ λͺ¨λ νμΌμ κ²½λ‘μ λͺ¨λμ μ΄λ¦μ #μΌλ‘ ꡬλΆν΄ κΈ°μ¬ν©λλ€. μ΄ν μ΄ νλ‘μ νΈκ° λΉλλ λ editor.module.ts, editor.css, editor.jsνμΌλ€μ src-app-modules-editor.module.jsλ‘ λ¬Άμ¬ λ³λμ νμΌλ‘ λΆλ¦¬λ©λλ€. μ΄μ μλμ μ½λλ‘ μμ§μ
μλν°μ μμ±μλ₯Ό λμ μΌλ‘ μ»μ΄μ¬ μ μμ΅λλ€.
@Component({...})
export class AppComponent {
title = 'app';
@ViewChild('textarea') el: ElementRef;
constructor(private injector: Injector, private loader: NgModuleFactoryLoader) {}
onClickLoadEditor() {
this.loader.load('src/app/modules/editor.module#EditorModule')
.then(factory => factory.create(this.injector).instance.load())
.then(({Editor}) => new Editor(this.el.nativeElement));
}
}
μ¬μ€ Angular@v5 μ΄νμμλ webpackμ΄ κΈ°λ³Έμ μΌλ‘ μ¬μ©νλ System.importνμ νλ¬κ·ΈμΈμΌλ‘ .tsνμΌ λΏλ§ μλ μ¬λ¬ νμΌμ λμ μΌλ‘ κ°λ¨ν λΆλ¦¬ν μ μμμ΅λλ€. νμ§λ§ [email protected] λΆν° webpackμ΄ System.importνμ νλ¬κ·ΈμΈμ μ¬μ©νμ§ μκ² λμκ³ . Angular@v6 λ²μ μ΄νλΆν°λ ν΄λΉ μ½λκ° λ°κ²¬λλ©΄ μ»΄νμΌ μμ μ κ²½κ³ λ₯Ό μΆλ ₯ν©λλ€. κ·Έλ κΈ° λλ¬Έμ System.importλ₯Ό μ§μ μ μΌλ‘ μ¬μ©ν μ μκ³ λ³Έλ¬Έκ³Ό κ°μ΄ NgModuleFactoryLoaderλ₯Ό μ¬μ©ν΄μΌ ν©λλ€.
μ¬λ―Έμλ κ²μ NgModuleFactoryLoaderμ ꡬνμ²΄μΈ SystemJsNgModuleLoaderλ΄λΆμμλ System.importλ₯Ό μμ§ μ¬μ©νκ³ μλ€λ κ²μ
λλ€. 곡μ githubμμλ μ΄ μ½λλ₯Ό typescriptμ importλ¬Έμ μ¬μ©νλ κ²μΌλ‘ μμ νλ €λ PRμ΄ μμ΅λλ€. μ΄ PRμ΄ λ¨Έμ§λλ€κ³ νλλΌλ. μ λ°©λ²μ μ΄μ©νλ λ° λ¬Έμ λ μμ΅λλ€.