// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddInstance(Configuration); // Add WebMarkupMin services to the services container. services.AddWebMarkupMin(options => { options.AllowMinificationInDevelopmentEnvironment = true; options.AllowCompressionInDevelopmentEnvironment = true; }) .AddHtmlMinification(options => { options.ExcludedPages = new List <IUrlMatcher> { new WildcardUrlMatcher("/minifiers/x*ml-minifier"), new ExactUrlMatcher("/contact") }; HtmlMinificationSettings settings = options.MinificationSettings; settings.RemoveRedundantAttributes = true; settings.RemoveHttpProtocolFromAttributes = true; settings.RemoveHttpsProtocolFromAttributes = true; options.CssMinifierFactory = new MsAjaxCssMinifierFactory(); options.JsMinifierFactory = new MsAjaxJsMinifierFactory(); }) .AddXhtmlMinification(options => { options.IncludedPages = new List <IUrlMatcher> { new WildcardUrlMatcher("/minifiers/x*ml-minifier"), new ExactUrlMatcher("/contact") }; XhtmlMinificationSettings settings = options.MinificationSettings; settings.RemoveRedundantAttributes = true; settings.RemoveHttpProtocolFromAttributes = true; settings.RemoveHttpsProtocolFromAttributes = true; options.CssMinifierFactory = new YuiCssMinifierFactory(); options.JsMinifierFactory = new YuiJsMinifierFactory(); }) .AddXmlMinification(options => { XmlMinificationSettings settings = options.MinificationSettings; settings.CollapseTagsWithoutContent = true; }) .AddHttpCompression() ; // Add framework services. services.AddMvc(); // Add WebMarkupMin sample services to the services container. services.AddSingleton <SitemapService>(); services.AddSingleton <CssMinifierFactory>(); services.AddSingleton <JsMinifierFactory>(); services.AddSingleton <HtmlMinificationService>(); services.AddSingleton <XhtmlMinificationService>(); services.AddSingleton <XmlMinificationService>(); }
public static void Configure(WebMarkupMinConfiguration configuration) { configuration.AllowMinificationInDebugMode = true; configuration.AllowCompressionInDebugMode = true; DefaultCssMinifierFactory.Current = new MsAjaxCssMinifierFactory(); DefaultJsMinifierFactory.Current = new MsAjaxJsMinifierFactory(); IHtmlMinificationManager htmlMinificationManager = HtmlMinificationManager.Current; HtmlMinificationSettings htmlMinificationSettings = htmlMinificationManager.MinificationSettings; htmlMinificationSettings.RemoveRedundantAttributes = true; htmlMinificationSettings.RemoveHttpProtocolFromAttributes = true; htmlMinificationSettings.RemoveHttpsProtocolFromAttributes = true; IXhtmlMinificationManager xhtmlMinificationManager = XhtmlMinificationManager.Current; XhtmlMinificationSettings xhtmlMinificationSettings = xhtmlMinificationManager.MinificationSettings; xhtmlMinificationSettings.RemoveRedundantAttributes = true; xhtmlMinificationSettings.RemoveHttpProtocolFromAttributes = true; xhtmlMinificationSettings.RemoveHttpsProtocolFromAttributes = true; IXmlMinificationManager xmlMinificationManager = XmlMinificationManager.Current; XmlMinificationSettings xmlMinificationSettings = xmlMinificationManager.MinificationSettings; xmlMinificationSettings.CollapseTagsWithoutContent = true; IHttpCompressionManager httpCompressionManager = HttpCompressionManager.Current; httpCompressionManager.CompressorFactories = new List <ICompressorFactory> { new DeflateCompressorFactory(), new GZipCompressorFactory() }; }
public static void Register(IServiceCollection services) { services.AddWebMarkupMin(options => { options.AllowMinificationInDevelopmentEnvironment = true; options.AllowCompressionInDevelopmentEnvironment = true; }) .AddHtmlMinification(options => { options.ExcludedPages = new List <IUrlMatcher> { new WildcardUrlMatcher("/minifiers/x*ml-minifier") }; HtmlMinificationSettings settings = options.MinificationSettings; settings.RemoveRedundantAttributes = true; settings.RemoveHttpProtocolFromAttributes = true; settings.RemoveHttpsProtocolFromAttributes = true; options.CssMinifierFactory = new NUglifyCssMinifierFactory(); options.JsMinifierFactory = new NUglifyJsMinifierFactory(); }) .AddXhtmlMinification(options => { options.IncludedPages = new List <IUrlMatcher> { new WildcardUrlMatcher("/minifiers/x*ml-minifier"), new ExactUrlMatcher("/contact") }; XhtmlMinificationSettings settings = options.MinificationSettings; settings.RemoveRedundantAttributes = true; settings.RemoveHttpProtocolFromAttributes = true; settings.RemoveHttpsProtocolFromAttributes = true; options.CssMinifierFactory = new KristensenCssMinifierFactory(); options.JsMinifierFactory = new CrockfordJsMinifierFactory(); }) .AddXmlMinification(options => { XmlMinificationSettings settings = options.MinificationSettings; settings.CollapseTagsWithoutContent = true; }) .AddHttpCompression(options => { options.CompressorFactories = new List <ICompressorFactory> { new GZipCompressorFactory(new GZipCompressionSettings { Level = CompressionLevel.Fastest }), new DeflateCompressorFactory(new DeflateCompressionSettings { Level = CompressionLevel.Fastest }) }; }); }
/// <summary> /// Constructs a instance of XML minification manager /// </summary> /// <param name="settings">XML minification settings</param> /// <param name="logger">Logger</param> public XmlMinificationManager(XmlMinificationSettings settings, ILogger logger) { MinificationSettings = settings; SupportedMediaTypes = new HashSet <string>(MediaTypeGroupConstants.Xml); IncludedPages = new List <IUrlMatcher>(); ExcludedPages = new List <IUrlMatcher>(); Logger = logger; }
public static void AddWebMarkupMinConfigure(this IServiceCollection services) { services.AddWebMarkupMin( options => { options.AllowMinificationInDevelopmentEnvironment = true; options.AllowCompressionInDevelopmentEnvironment = true; }) .AddHtmlMinification( options => { options.MinificationSettings.RemoveRedundantAttributes = false; options.MinificationSettings.RemoveHttpProtocolFromAttributes = false; options.MinificationSettings.RemoveHttpsProtocolFromAttributes = false; }) .AddXhtmlMinification(options => { options.IncludedPages = new List <IUrlMatcher> { new WildcardUrlMatcher("/minifiers/x*ml-minifier"), new ExactUrlMatcher("/rss") }; XhtmlMinificationSettings settings = options.MinificationSettings; settings.RemoveRedundantAttributes = true; settings.RemoveHttpProtocolFromAttributes = true; settings.RemoveHttpsProtocolFromAttributes = true; }) .AddXmlMinification(options => { XmlMinificationSettings settings = options.MinificationSettings; settings.CollapseTagsWithoutContent = true; }) .AddHttpCompression(options => { options.CompressorFactories = new List <ICompressorFactory> { new DeflateCompressorFactory(new DeflateCompressionSettings { Level = CompressionLevel.Fastest }), new GZipCompressorFactory(new GZipCompressionSettings { Level = CompressionLevel.Fastest }) }; }); }
/// <summary> /// Constructs instance of XML minifier /// </summary> /// <param name="settings">XML minification settings</param> /// <param name="logger">Logger</param> public XmlMinifier(XmlMinificationSettings settings = null, ILogger logger = null) { _settings = settings ?? new XmlMinificationSettings(); _logger = logger ?? new NullLogger(); _xmlParser = new XmlParser(new XmlParsingHandlers { XmlDeclaration = XmlDeclarationHandler, ProcessingInstruction = ProcessingInstructionHandler, Doctype = DoctypeDelegateHandler, Comment = CommentHandler, CdataSection = CdataSectionHandler, StartTag = StartTagHandler, EndTag = EndTagHandler, EmptyTag = EmptyTagHandler, Text = TextHandler }); }
// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services.AddSingleton(Configuration); // Add WebMarkupMin services to the services container. services.AddWebMarkupMin(options => { options.AllowMinificationInDevelopmentEnvironment = true; options.AllowCompressionInDevelopmentEnvironment = true; }) .AddHtmlMinification(options => { options.ExcludedPages = new List <IUrlMatcher> { new WildcardUrlMatcher("/minifiers/x*ml-minifier"), new ExactUrlMatcher("/contact") }; HtmlMinificationSettings settings = options.MinificationSettings; settings.RemoveRedundantAttributes = true; settings.RemoveHttpProtocolFromAttributes = true; settings.RemoveHttpsProtocolFromAttributes = true; options.CssMinifierFactory = new MsAjaxCssMinifierFactory(); options.JsMinifierFactory = new MsAjaxJsMinifierFactory(); }) .AddXhtmlMinification(options => { options.IncludedPages = new List <IUrlMatcher> { new WildcardUrlMatcher("/minifiers/x*ml-minifier"), new ExactUrlMatcher("/contact") }; XhtmlMinificationSettings settings = options.MinificationSettings; settings.RemoveRedundantAttributes = true; settings.RemoveHttpProtocolFromAttributes = true; settings.RemoveHttpsProtocolFromAttributes = true; options.CssMinifierFactory = new YuiCssMinifierFactory(); options.JsMinifierFactory = new YuiJsMinifierFactory(); }) .AddXmlMinification(options => { XmlMinificationSettings settings = options.MinificationSettings; settings.CollapseTagsWithoutContent = true; }) .AddHttpCompression(options => { options.CompressorFactories = new List <ICompressorFactory> { new BrotliCompressorFactory(new BrotliCompressionSettings { Level = 1 }), new DeflateCompressorFactory(new DeflateCompressionSettings { Level = CompressionLevel.Fastest }), new GZipCompressorFactory(new GZipCompressionSettings { Level = CompressionLevel.Fastest }) }; }) ; // Override the default logger for WebMarkupMin. services.AddSingleton <IWmmLogger, WmmThrowExceptionLogger>(); // Add framework services. var manager = new ApplicationPartManager(); manager.ApplicationParts.Add(new AssemblyPart(typeof(Startup).Assembly)); services.AddSingleton(manager); services.AddMvc(options => { options.CacheProfiles.Add("CacheCompressedContent5Minutes", new CacheProfile { NoStore = HostingEnvironment.IsDevelopment(), Duration = 300, Location = ResponseCacheLocation.Client, VaryByHeader = "Accept-Encoding" } ); }); // Add WebMarkupMin sample services to the services container. services.AddSingleton <SitemapService>(); services.AddSingleton <CssMinifierFactory>(); services.AddSingleton <JsMinifierFactory>(); services.AddSingleton <HtmlMinificationService>(); services.AddSingleton <XhtmlMinificationService>(); services.AddSingleton <XmlMinificationService>(); }
/// <summary> /// Minifies the XML content. /// </summary> /// <param name="useEmptyMinificationSettings"> /// Boolean to specify whether to use empty minification settings. /// Default value is <c>false</c>, this will use commonly accepted settings. /// </param> public MinifyXml(bool useEmptyMinificationSettings = false) { // https://github.com/Taritsyn/WebMarkupMin/wiki/XML-Minifier _minificationSettings = new XmlMinificationSettings(useEmptyMinificationSettings); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddSingleton(Configuration); // Add response caching service. services.AddResponseCaching(); // Add WebMarkupMin services to the services container. services.AddWebMarkupMin(options => { options.AllowMinificationInDevelopmentEnvironment = true; options.AllowCompressionInDevelopmentEnvironment = true; }) .AddHtmlMinification(options => { options.ExcludedPages = new List <IUrlMatcher> { new RegexUrlMatcher(@"^/minifiers/x(?:ht)?ml-minifier$"), new ExactUrlMatcher("/contact") }; HtmlMinificationSettings settings = options.MinificationSettings; settings.RemoveRedundantAttributes = true; settings.RemoveHttpProtocolFromAttributes = true; settings.RemoveHttpsProtocolFromAttributes = true; options.CssMinifierFactory = new NUglifyCssMinifierFactory(); options.JsMinifierFactory = new NUglifyJsMinifierFactory(); }) .AddXhtmlMinification(options => { options.IncludedPages = new List <IUrlMatcher> { new RegexUrlMatcher(@"^/minifiers/x(?:ht)?ml-minifier$"), new ExactUrlMatcher("/contact") }; XhtmlMinificationSettings settings = options.MinificationSettings; settings.RemoveRedundantAttributes = true; settings.RemoveHttpProtocolFromAttributes = true; settings.RemoveHttpsProtocolFromAttributes = true; options.CssMinifierFactory = new KristensenCssMinifierFactory(); options.JsMinifierFactory = new CrockfordJsMinifierFactory(); }) .AddXmlMinification(options => { XmlMinificationSettings settings = options.MinificationSettings; settings.CollapseTagsWithoutContent = true; }) .AddHttpCompression(options => { options.CompressorFactories = new List <ICompressorFactory> { new BrotliCompressorFactory(new BrotliCompressionSettings { Level = 1 }), new DeflateCompressorFactory(new DeflateCompressionSettings { Level = CompressionLevel.Fastest }), new GZipCompressorFactory(new GZipCompressionSettings { Level = CompressionLevel.Fastest }) }; }) ; // Override the default logger for WebMarkupMin. services.AddSingleton <IWmmLogger, WmmThrowExceptionLogger>(); services.Configure <CookiePolicyOptions>(options => { // This lambda determines whether user consent for non-essential cookies is needed for a given request. options.CheckConsentNeeded = context => true; options.MinimumSameSitePolicy = SameSiteMode.None; }); // Add framework services. services.AddMvc(options => { options.CacheProfiles.Add("CacheCompressedContent5Minutes", new CacheProfile { NoStore = HostingEnvironment.IsDevelopment(), Duration = 300, Location = ResponseCacheLocation.Any, VaryByHeader = "Accept-Encoding" } ); }).SetCompatibilityVersion(CompatibilityVersion.Version_2_1); // Add WebMarkupMin sample services to the services container. services.AddSingleton <SitemapService>(); services.AddSingleton <CssMinifierFactory>(); services.AddSingleton <JsMinifierFactory>(); services.AddSingleton <HtmlMinificationService>(); services.AddSingleton <XhtmlMinificationService>(); services.AddSingleton <XmlMinificationService>(); }
/// <summary> /// Constructs a instance of XML minification manager /// </summary> /// <param name="settings">XML minification settings</param> /// <param name="logger">Logger</param> public XmlMinificationManager(XmlMinificationSettings settings, ILogger logger) { MinificationSettings = settings; SupportedMediaTypes = new HashSet <string>(MediaTypeGroupConstants.Xml); Logger = logger; }
// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services.AddSingleton(Configuration); // Add WebMarkupMin services to the services container. services.AddWebMarkupMin(options => { options.AllowMinificationInDevelopmentEnvironment = true; options.AllowCompressionInDevelopmentEnvironment = true; }) .AddHtmlMinification(options => { options.ExcludedPages = new List <IUrlMatcher> { new RegexUrlMatcher(@"^/minifiers/x(?:ht)?ml-minifier$"), new ExactUrlMatcher("/contact") }; HtmlMinificationSettings settings = options.MinificationSettings; settings.RemoveRedundantAttributes = true; settings.RemoveHttpProtocolFromAttributes = true; settings.RemoveHttpsProtocolFromAttributes = true; options.CssMinifierFactory = new NUglifyCssMinifierFactory(); options.JsMinifierFactory = new NUglifyJsMinifierFactory(); }) .AddXhtmlMinification(options => { options.IncludedPages = new List <IUrlMatcher> { new RegexUrlMatcher(@"^/minifiers/x(?:ht)?ml-minifier$"), new ExactUrlMatcher("/contact") }; XhtmlMinificationSettings settings = options.MinificationSettings; settings.RemoveRedundantAttributes = true; settings.RemoveHttpProtocolFromAttributes = true; settings.RemoveHttpsProtocolFromAttributes = true; options.CssMinifierFactory = new KristensenCssMinifierFactory(); options.JsMinifierFactory = new CrockfordJsMinifierFactory(); }) .AddXmlMinification(options => { XmlMinificationSettings settings = options.MinificationSettings; settings.CollapseTagsWithoutContent = true; }) .AddHttpCompression(options => { options.CompressorFactories = new List <ICompressorFactory> { new DeflateCompressorFactory(new DeflateCompressionSettings { Level = CompressionLevel.Fastest }), new GZipCompressorFactory(new GZipCompressionSettings { Level = CompressionLevel.Fastest }) }; }) ; // Add framework services. services.AddMvc(options => { options.CacheProfiles.Add("CacheCompressedContent5Minutes", new CacheProfile { NoStore = HostingEnvironment.IsDevelopment(), Duration = 300, Location = ResponseCacheLocation.Client, VaryByHeader = "Accept-Encoding" } ); }); // Add WebMarkupMin sample services to the services container. services.AddSingleton <SitemapService>(); services.AddSingleton <CssMinifierFactory>(); services.AddSingleton <JsMinifierFactory>(); services.AddSingleton <HtmlMinificationService>(); services.AddSingleton <XhtmlMinificationService>(); services.AddSingleton <XmlMinificationService>(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { // Add framework services. // Add the localization services to the services container services.AddLocalization(options => options.ResourcesPath = "Resources"); //services.AddWebMarkupMin( // options => // { // options.AllowMinificationInDevelopmentEnvironment = true; // options.AllowCompressionInDevelopmentEnvironment = true; // }) // .AddHtmlMinification( // options => // { // options.MinificationSettings.RemoveRedundantAttributes = true; // options.MinificationSettings.RemoveHttpProtocolFromAttributes = true; // options.MinificationSettings.RemoveHttpsProtocolFromAttributes = true; // }) // .AddHttpCompression(); //services.Configure<GzipCompressionProviderOptions> // (options => options.Level = CompressionLevel.Optimal); // services.AddResponseCompression(options => // { // options.Providers.Add<GzipCompressionProvider>(); // }); // Add WebMarkupMin services. services.AddWebMarkupMin(options => { options.AllowMinificationInDevelopmentEnvironment = true; options.AllowCompressionInDevelopmentEnvironment = true; }) .AddHtmlMinification(options => { HtmlMinificationSettings settings = options.MinificationSettings; settings.RemoveRedundantAttributes = true; settings.RemoveHttpProtocolFromAttributes = true; settings.RemoveHttpsProtocolFromAttributes = true; }) .AddXhtmlMinification(options => { XhtmlMinificationSettings settings = options.MinificationSettings; settings.RemoveRedundantAttributes = true; settings.RemoveHttpProtocolFromAttributes = true; settings.RemoveHttpsProtocolFromAttributes = true; options.CssMinifierFactory = new KristensenCssMinifierFactory(); options.JsMinifierFactory = new CrockfordJsMinifierFactory(); }) .AddXmlMinification(options => { XmlMinificationSettings settings = options.MinificationSettings; settings.CollapseTagsWithoutContent = true; }) .AddHttpCompression(options => { options.CompressorFactories = new List <ICompressorFactory> { new DeflateCompressorFactory(new DeflateCompressionSettings { Level = CompressionLevel.Fastest }), new GZipCompressorFactory(new GZipCompressionSettings { Level = CompressionLevel.Fastest }) }; }); services.AddMvc() // Add support for finding localized views, based on file name suffix, e.g. Index.fr.cshtml .AddViewLocalization( LanguageViewLocationExpanderFormat.Suffix, opts => { opts.ResourcesPath = "Resources"; } ) // Add support for localizing strings in data annotations (e.g. validation messages) via the // IStringLocalizer abstractions. .AddDataAnnotationsLocalization(); // Configure supported cultures and localization options services.Configure <RequestLocalizationOptions>(options => { var supportedCultures = new[] { new CultureInfo("en-US"), new CultureInfo("pt-BR") }; // State what the default culture for your application is. This will be used if no specific culture // can be determined for a given request. options.DefaultRequestCulture = new RequestCulture(CultureInfo.CurrentCulture);//culture: "en-US", uiCulture: "en-US"); // You must explicitly state which cultures your application supports. // These are the cultures the app supports for formatting numbers, dates, etc. options.SupportedCultures = supportedCultures; // These are the cultures the app supports for UI strings, i.e. we have localized resources for. options.SupportedUICultures = supportedCultures; // You can change which providers are configured to determine the culture for requests, or even add a custom // provider with your own logic. The providers will be asked in order to provide a culture for each request, // and the first to provide a non-null result that is in the configured supported cultures list will be used. // By default, the following built-in providers are configured: // - QueryStringRequestCultureProvider, sets culture via "culture" and "ui-culture" query string values, useful for testing // - CookieRequestCultureProvider, sets culture via "ASPNET_CULTURE" cookie // - AcceptLanguageHeaderRequestCultureProvider, sets culture via the "Accept-Language" request header //options.RequestCultureProviders.Insert(0, new CustomRequestCultureProvider(async context => //{ // // My custom request culture logic // return new ProviderCultureResult("en"); //})); }); }