Html 5 manifest is not working by iFrame correctly
Asked Answered
W

1

10

I've an application which has several C# projects, as following

  • CRM.DomainLogic
  • CRM.Web
  • Warehouse.DomainLogic
  • Warehouse.Web
  • ,...

Each web project such as CRM.Web has its own 'html views' and 'js controllers' and there are several other types of static files.

To make deployment easier I'd like to use Html5 manifest.

So, To make separated deployment across projects possible, I've used iframes. As a result with changes of CRM.Web, clients will get CRM files, and there is no need to download Warehouse.Web files again!

Steps:

1- I've a Web API method that returns all names of Web assemblies, for example CRM.Web and Warehouse.Web

2- I've another Web API method that gets the assembly name as a parameter and return manifest file content which points to files which are located on that project.

public HttpResponseMessage GetManifestByAssemblyName(String assemblyName)

Codes are omitted here.

response.Content = new StringContent(manifestBody.ToString(), Encoding.UTF8, "text/cache-manifest");

3- at client side I create a new iFrame for each assembly and set the src to another web api method which return html body that it's manifest is assigned to the address of WebAPI method that returns manifest body(GetManifestByAssemblyName)

    String result = String.Format
        (@"<html manifest='{0}'> </html>", "/api/AppManifest/GetManifestByAssemblyName?assemblyName=" + assemblyName + ".manifest");

    response.Content = new StringContent(result, UTF8Encoding.Default, "text/html");

The code of iFrames:

var htmlPageUrl = "/api/AppManifest/GetHtmlContainerForManifestByName?assemblyName=" + name;

                    var iFrame = document.createElement("iFrame");
                    iFrame.setAttribute("src", htmlPageUrl);
                    iFrame.setAttribute("sandbox", "allow-same-origin");
                    iFrame.setAttribute("seamless", "seamless");
                    document.body.appendChild(iFrame);

When I run application, it gets assembly names, and then creates iFrames, and each iFrame gets its own manifest automatically.

But the window.applicatioCache.status is 0 which means it has no cache.

When I go resources page, I can see followings:

enter image description here

But when I request one of those files which are cached, the request will not use cache.

I know that there is no reference for my work on the web and this is totally based on my ideas, and I know some security restrictions may appear here, but is there any solution to fix a problem?

Thanks in advance.

Note: You can download sample application source code here.

Then press Ctrl+S to save the file, and read Index.html notes first.

Wolver answered 18/2, 2014 at 13:21 Comment(0)
N
1

I tried your sample project. I had to change sandbox attribute to allow-scripts because otherwise Chrome was blocking JS execution from the iFrame.

Apart from that, I think your cache is working fine. See below screenshot. enter image description here

I think the root cause of your confusion is that you're checking the main document's appCache status, which doesn't have a manifest. The manifest is for document loaded in iFrame. So in Chrome, if you switch to the individual iFrame and check status, it shows Idle (1) which means cache is active! See below:

enter image description here

Hope this helps!

Nahama answered 2/9, 2014 at 14:46 Comment(1)
Run following command on console: $.ajax('/api/AppManifest/GetResByName?resName=CRM.Web.Models.Customer.js'); and unfortunately it sends request to the server instead of loading that from cached manifest.Wolver

© 2022 - 2024 — McMap. All rights reserved.