禁用 HTML5 除 IE 之外的所有浏览器的 AppCache

Disable HTML5 AppCache Of All browser Except IE

我有一个基于 Angular 的 PWA 应用程序(基于 service-worker),它在所有现代浏览器中都可以离线正常工作,为了支持 IE,我添加了 "manifest.appcache" 使 IE 可以离线工作通过 HTML5 应用程序缓存。

有什么方法可以在除 IE 之外的所有其他浏览器中禁用 Appcache 吗?目前在现代浏览器中 Appcache 也与 service worker 一起工作

我试过下面

<html lang="en" manifest="manifest.appcache" *ngIf="isIE">
<html lang="en" *ngIf="!isIE">

在组件中

const isIE = /msie\s|trident/i.test(window.navigator.userAgent);

但似乎 HTML 在 isIE

的组件设置值之前呈现

我尝试搜索但没有找到解决此问题的方法。

除了 IE 浏览器,我没有找到任何方法来禁用其他浏览器的 AppCache。

即使您设法删除清单属性,浏览器也会使用 Appcache。

禁用它的唯一方法是从服务器中删除清单文件,这也会禁用 IE 浏览器的 Appcache。 See here.

我建议您在 IE window 上显示一条消息,说明您的应用不支持 IE 浏览器的离线模式,并建议您的客户使用最新的 Microsoft 浏览器。

我没有在 IE 上测试过,但是从这个 SO answer 看来,如果 manifest 设置为客户端,它似乎不会工作。

在这种情况下,您可以使用 angular 通用设置此属性服务器端。

import {Request} from 'express';
import {REQUEST} from '@nguniversal/express-engine/tokens';

public constructor(@Inject(PLATFORM_ID) private platformId, 
            @Optional() @Inject(REQUEST) protected request: Request,
            @Inject(DOCUMENT) private  doc: Document, private renderer: Renderer2)
    {

        if(!isPlatformBrowser(platformId))
        {
          const isIE = /msie\s|trident/i.test(request.headers['user-agent']);
          if(isIE)
          {
            this.renderer.setAttribute(this.doc.documentElement,"manifest","manifest.appcache");
          }
        }

如果您不使用 angular 通用并且 cannot/do 不想使用它,您需要在返回它之前找到一些其他方法来修改 index.html 文件服务器端。