小编Fab*_*osa的帖子

链接样式表预加载与W3C验证

我正在努力满足2个跳棋:W3C验证器谷歌页面洞察力

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.

css w3c-validation preload google-pagespeed

3
推荐指数
1
解决办法
1304
查看次数

使用 useFactory 提供服务时不会触发 ngOnDestroy

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)

angular

3
推荐指数
1
解决办法
1519
查看次数

标签 统计

angular ×1

css ×1

google-pagespeed ×1

preload ×1

w3c-validation ×1