Merge pull request #552 from sbwalker/master

fixed stylesheet and script removal logic
This commit is contained in:
Shaun Walker 2020-05-28 09:43:23 -04:00 committed by GitHub
commit e80f42f1d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 4 deletions

View File

@ -24,6 +24,7 @@
}
// include page resources
string batch = DateTime.Now.ToString("yyyyMMddHHmmssfff");
var links = new List<object>();
var scripts = new List<object>();
foreach (Resource resource in PageState.Page.Resources)
@ -31,18 +32,18 @@
switch (resource.ResourceType)
{
case ResourceType.Stylesheet:
links.Add(new { id = "app-stylesheet" + links.Count.ToString("00"), rel = "stylesheet", href = resource.Url, type = "text/css", integrity = resource.Integrity ?? "", crossorigin = resource.CrossOrigin ?? "", key = "" });
links.Add(new { id = "app-stylesheet-" + batch + "-" + (links.Count + 1).ToString("00"), rel = "stylesheet", href = resource.Url, type = "text/css", integrity = resource.Integrity ?? "", crossorigin = resource.CrossOrigin ?? "", key = "" });
break;
case ResourceType.Script:
scripts.Add(new { id = "app-script" + scripts.Count.ToString("00"), src = resource.Url, integrity = resource.Integrity ?? "", crossorigin = resource.CrossOrigin ?? "", content = "", location = "body", key = "" });
scripts.Add(new { id = "app-script-" + batch + "-" + (scripts.Count + 1).ToString("00"), src = resource.Url, integrity = resource.Integrity ?? "", crossorigin = resource.CrossOrigin ?? "", content = "", location = "body", key = "" });
break;
}
}
await interop.IncludeLinks(links.ToArray());
await interop.IncludeScripts(scripts.ToArray());
// remove any page resource references which are no longer required for this page
await interop.RemoveElementsById("app-stylesheet", "app-stylesheet" + links.Count.ToString("00"), "");
await interop.RemoveElementsById("app-script", "app-script" + scripts.Count.ToString("00"), "");
await interop.RemoveElementsById("app-stylesheet", "", "app-stylesheet-" + batch + "-00");
await interop.RemoveElementsById("app-script", "", "app-script-" + batch + "-00");
// add favicon
if (PageState.Site.FaviconFileId != null)

View File

@ -45,6 +45,9 @@ Oqtane.Interop = {
document.head.appendChild(meta);
}
else {
if (id !== "") {
meta.setAttribute("id", id);
}
if (meta.content !== content) {
meta.setAttribute("content", content);
}
@ -77,6 +80,9 @@ Oqtane.Interop = {
document.head.appendChild(link);
}
else {
if (link.id !== id) {
link.setAttribute('id', id);
}
if (link.rel !== rel) {
link.setAttribute('rel', rel);
}
@ -148,6 +154,9 @@ Oqtane.Interop = {
});
}
else {
if (script.id !== id) {
script.setAttribute('id', id);
}
if (src !== "") {
if (script.src !== this.getAbsoluteUrl(src)) {
script.removeAttribute('integrity');