public void testPreservePatterns() { var source = Resources.testPreservePatterns; var result = Resources.testPreservePatternsResult; var preservePatterns = new List <Regex> { HtmlCompressor.PHP_TAG_PATTERN, HtmlCompressor.SERVER_SCRIPT_TAG_PATTERN, HtmlCompressor.SERVER_SIDE_INCLUDE_PATTERN, new Regex("<jsp:.*?>", RegexOptions.Singleline | RegexOptions.IgnoreCase) }; //<?php ... ?> blocks //<% ... %> blocks //<!--# ... --> blocks //<jsp: ... > tags var compressor = new HtmlCompressor(); compressor.setPreservePatterns(preservePatterns); compressor.setRemoveComments(true); compressor.setRemoveIntertagSpaces(true); var compress = compressor.compress(source); Assert.AreEqual(result, compress); }
public GoogleHtmlMinificationService() { _compressor = new HtmlCompressor(); _compressor.setEnabled(true); _compressor.setRemoveComments(true); _compressor.setRemoveMultiSpaces(true); _compressor.setRemoveIntertagSpaces(true); }
public void testRemoveComments() { var source = Resources.testRemoveComments; var result = Resources.testRemoveCommentsResult; var compressor = new HtmlCompressor(); compressor.setRemoveComments(true); compressor.setRemoveIntertagSpaces(true); var compress = compressor.compress(source); Assert.AreEqual(result, compress); }
public static async Task Run( [QueueTrigger(QueueName.RenderPage)] RenderPage command, [Blob(ContainerName.PageTemplate + "/{" + nameof(RenderPage.TemplateId) + "}", FileAccess.Read)] CloudBlockBlob pageTemplateBlob, [Blob(ContainerName.PageData + "/{" + nameof(RenderPage.DataInstanceId) + "}", FileAccess.ReadWrite)] CloudBlockBlob pageDataBlob, [Blob(ContainerName.WebHost + "/{" + nameof(RenderPage.PublicUrl) + "}", FileAccess.Write)] CloudBlockBlob pageHtmlBlob, [Queue(QueueName.CopyBlob)] CloudQueue copyQueue, ILogger log) { log.LogInformation(JsonConvert.SerializeObject(command)); var copyQueueService = new CommandQueueService(copyQueue); var pageData = JsonConvert.DeserializeObject(await pageDataBlob.DownloadTextAsync()); var pageTemplate = await pageTemplateBlob.DownloadTextAsync(); var html = Render.StringToString(pageTemplate, pageData, new RenderContextBehaviour { HtmlEncoder = text => text }); var compressor = new HtmlCompressor(); compressor.setEnabled(true); compressor.setRemoveComments(true); compressor.setRemoveMultiSpaces(true); compressor.setRemoveIntertagSpaces(true); html = compressor.compress(html); await pageHtmlBlob.UploadTextAsync(html); pageHtmlBlob.Properties.ContentType = "text/html"; await pageHtmlBlob.SetPropertiesAsync(); var copyCommand = new CopyBlob { Path = command.PublicUrl }; await Task.WhenAll( pageDataBlob.DeleteAsync(), copyQueueService.SubmitCommandAsync(copyCommand) ); }
/// <summary> /// Compresses and minifies HTML Content /// </summary> /// <param name="HtmlInput">The original HTML Content</param> /// <returns>Compressed HTML</returns> public static string HTMLCompress(string HtmlInput) { string ret = HtmlInput; try { HtmlCompressor htmlCompressor = new HtmlCompressor(); htmlCompressor.setRemoveComments(true); ret = htmlCompressor.compress(HtmlInput); } catch (Exception ex) { //throw ex; } return(ret); }
public override void OnActionExecuting(ActionExecutingContext filterContext) { var response = filterContext.HttpContext.Response; if (response.Filter == null) { return; } HtmlCompressor compressor = new HtmlCompressor(); ResponseFilterStream filter = new ResponseFilterStream(response.Filter); compressor.setRemoveComments(true); compressor.setCssCompressor(new CssCompressor(filterContext.HttpContext)); compressor.setCompressCss(true); compressor.setJavaScriptCompressor(new JsCompressor(filterContext.HttpContext)); compressor.setCompressJavaScript(true); filter.TransformString += s => { return(compressor.compress(s)); }; response.Filter = filter; }
public void testRemoveComments() { var source = Resources.testRemoveComments; var result = Resources.testRemoveCommentsResult; var compressor = new HtmlCompressor(); compressor.setRemoveComments(true); compressor.setRemoveIntertagSpaces(true); var compress = compressor.compress(source); Assert.AreEqual(result, compress); }
public void testPreservePatterns() { var source = Resources.testPreservePatterns; var result = Resources.testPreservePatternsResult; var preservePatterns = new List<Regex> { HtmlCompressor.PHP_TAG_PATTERN, HtmlCompressor.SERVER_SCRIPT_TAG_PATTERN, HtmlCompressor.SERVER_SIDE_INCLUDE_PATTERN, new Regex("<jsp:.*?>", RegexOptions.Singleline | RegexOptions.IgnoreCase) }; //<?php ... ?> blocks //<% ... %> blocks //<!--# ... --> blocks //<jsp: ... > tags var compressor = new HtmlCompressor(); compressor.setPreservePatterns(preservePatterns); compressor.setRemoveComments(true); compressor.setRemoveIntertagSpaces(true); var compress = compressor.compress(source); Assert.AreEqual(result, compress); }
protected HtmlCompressor createCompressorClone() { HtmlCompressor clone = new HtmlCompressor(); //clone.setJavaScriptCompressor(javaScriptCompressor); //clone.setCssCompressor(cssCompressor); clone.setRemoveComments(_removeComments); clone.setRemoveMultiSpaces(_removeMultiSpaces); clone.setRemoveIntertagSpaces(_removeIntertagSpaces); clone.setRemoveQuotes(removeQuotes); //clone.setCompressJavaScript(compressJavaScript); clone.setCompressCss(compressCss); clone.setSimpleDoctype(_simpleDoctype); clone.setRemoveScriptAttributes(_removeScriptAttributes); clone.setRemoveStyleAttributes(_removeStyleAttributes); clone.setRemoveLinkAttributes(_removeLinkAttributes); clone.setRemoveFormAttributes(_removeFormAttributes); clone.setRemoveInputAttributes(_removeInputAttributes); clone.setSimpleBooleanAttributes(_simpleBooleanAttributes); //clone.setRemoveJavaScriptProtocol(removeJavaScriptProtocol); clone.setRemoveHttpProtocol(_removeHttpProtocol); clone.setRemoveHttpsProtocol(_removeHttpsProtocol); clone.setPreservePatterns(preservePatterns); clone.setYuiJsNoMunge(yuiJsNoMunge); clone.setYuiJsPreserveAllSemiColons(yuiJsPreserveAllSemiColons); clone.setYuiJsDisableOptimizations(yuiJsDisableOptimizations); clone.setYuiJsLineBreak(yuiJsLineBreak); clone.setYuiCssLineBreak(yuiCssLineBreak); //clone.setYuiErrorReporter(yuiErrorReporter); return clone; }