Disable HTML5 AppCache Of All browser Except IE

133 Views Asked by At

I have an Angular based PWA app (based on the service-worker) which is working fine offline in all modern browsers, To support IE I have added "manifest.appcache" which enable IE works offline by HTML5 App Cache.

Is there Any way which can disable Appcache in all other browsers except IE ? Currently in modern browsers Appcache is also working along with service worker

i have tried below

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

In component

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

But Seems HTML render before the component set value of the isIE

2

There are 2 best solutions below

0
David On BEST ANSWER

I haven't tested in on IE, but from this SO answer it looks like it will not work if the manifest is set client side.

In this case, then you can set this attribute server side using angular universal.

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");
          }
        }

If you are not using angular universal and cannot/do not want to use it, you need to find some other way to modify the index.html file server side before returning it.

2
Deepak-MSFT On

I tried to search but did not get any solution for this issue.

I did not get any way to disable the AppCache for other browsers except IE browser.

Even if you manage to remove the manifest attribute then also browser will use the Appcache.

The only way to disable it to remove the manifest file from the server which will also disable the Appcache for the IE browser. See here.

I suggest you show a message on the IE window that your app does not support offline mode for the IE browser and recommend your clients to use latest Microsoft browsers.