Google Page Insight建议我异步加载所有阻止CSS文件.好吧,我已经用预加载的方式重写了样式表文件包含,如下所示,并从头部延迟到正文的末尾:
...
<link rel="preload" href="mystyles.css" media="all" as="style"
onload="this.rel='stylesheet'"/>
</body>
Run Code Online (Sandbox Code Playgroud)
Google Page Insight迫使我从脑袋中取出它并将其放在身体末端.
好的,我可以对抗Google Page Insight.
但W3C Validator现在说我:
错误:链接元素不得显示为body元素的后代,除非link元素具有itemprop属性或具有rel属性,其值包含dns-prefetch,pingback,preconnect,prefetch,prerender或stylesheet
为什么"预加载"不被承认在rel属性中?我试图分配一个itemprop,但是不可能在同一个链接中有一个itemprop和一个rel.
HelloComponent获取一个SampleService实例,定义一个服务提供者。当HelloCompoment被摧毁时,我不明白为什么SampleService还能幸存。
如果按类型HelloComponent获取SampleService实例(避免ServiceProvider),则不会出现问题。
样本服务.ts
@Injectable()
export class SampleService implements OnDestroy{
constructor(){
console.log('created new sample service');
}
ngOnDestroy(){
console.log('destroyed sample service');
}
}
Run Code Online (Sandbox Code Playgroud)
你好组件.ts
import { Component, OnInit, OnDestroy } from '@angular/core'
import { SampleService } from '../service/sample.service'
let ServiceFactory = () => {
console.log('Providing new SampleService');
return new SampleService();
};
let ServiceProvider = {
provide: SampleService,
useFactory: ServiceFactory
};
@Component({
selector: 'hello',
templateUrl: './hello.component.html',
providers: [ServiceProvider]
})
export …Run Code Online (Sandbox Code Playgroud)