private void RewriteScriptTags(ResponseAnalysisContext context, string html) { foreach (var index in FastHtmlParser.FindAllTagIndexes(html, "script")) { var type = FastHtmlParser.GetAttributeValueAtTag(html, "type", index); if (!type.Equals("text/javascript", StringComparison.OrdinalIgnoreCase)) { continue; } // get content var inner = FastHtmlParser.GetInnerHtml(html, index, "script"); if (inner == null || inner.Value.Trim().Length == 0) { continue; } // compute hash var inline = ContentHashCache.GetOrAdd(inner.Value.Trim().TrimHtmlCdata().Trim().Value, v => CreateContent(v)); InlineContentService.TryAddScriptByHash(inline.Hash, inline.Content); // add change context.AddChange(TextChange.Remove(html, inner.Value.Offset, inner.Value.Length)); context.AddChange(FastHtmlParser.CreateInsertAttributeChange(html, index, "script", "src", $"/.waf/scripts/{inline.Hash}")); } }
private void RewriteStyleTags(ResponseAnalysisContext context, string html) { foreach (var index in FastHtmlParser.FindAllTagIndexes(html, "style")) { // get content var inner = FastHtmlParser.GetInnerHtml(html, index, "style"); if (inner == null) { continue; } // compute hash var inline = ContentHashCache.GetOrAdd(inner.Value.Trim().TrimHtmlCdata().Trim().Value, v => CreateContent(v)); InlineContentService.TryAddStyleByHash(inline.Hash, inline.Content); // add change var tagSpan = FastHtmlParser.GetFullTagSpan(html, index, "style"); context.AddChange(TextChange.Replace(html, index, tagSpan.Value.Length, inline.Tag)); } }