示例#1
0
        // 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()
            };
        }
示例#3
0
        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 XHTML minification manager
 /// </summary>
 /// <param name="settings">XHTML minification settings</param>
 /// <param name="cssMinifierFactory">CSS minifier factory</param>
 /// <param name="jsMinifierFactory">JS minifier factory</param>
 /// <param name="logger">Logger</param>
 public XhtmlMinificationManager(XhtmlMinificationSettings settings,
                                 ICssMinifierFactory cssMinifierFactory,
                                 IJsMinifierFactory jsMinifierFactory,
                                 ILogger logger)
 {
     MinificationSettings = settings;
     SupportedMediaTypes  = new HashSet <string>(MediaTypeGroupConstants.Xhtml);
     CssMinifierFactory   = cssMinifierFactory;
     JsMinifierFactory    = jsMinifierFactory;
     Logger = logger;
 }
        /// <summary>
        /// Constructs a instance of XHTML minification manager
        /// </summary>
        /// <param name="settings">XHTML minification settings</param>
        /// <param name="cssMinifierFactory">CSS minifier factory</param>
        /// <param name="jsMinifierFactory">JS minifier factory</param>
        /// <param name="logger">Logger</param>
        public XhtmlMinificationManager(XhtmlMinificationSettings settings,
                                        ICssMinifierFactory cssMinifierFactory,
                                        IJsMinifierFactory jsMinifierFactory,
                                        ILogger logger)
        {
            MinificationSettings = settings;
            SupportedMediaTypes  = new HashSet <string>(MediaTypeGroupConstants.Xhtml);
            IncludedPages        = new List <IUrlMatcher>();
            ExcludedPages        = new List <IUrlMatcher>();
            CssMinifierFactory   = cssMinifierFactory;
            JsMinifierFactory    = jsMinifierFactory;

            _logger = logger;
        }
示例#6
0
        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
                    })
                };
            });
        }
示例#7
0
        /// <summary>
        /// Constructs instance of XHTML minifier
        /// </summary>
        /// <param name="cssMinifier">CSS minifier</param>
        /// <param name="jsMinifier">JS minifier</param>
        /// <param name="settings">XHTML minification settings</param>
        /// <param name="logger">Logger</param>
        public XhtmlMinifier(XhtmlMinificationSettings settings = null, ICssMinifier cssMinifier = null,
                             IJsMinifier jsMinifier             = null, ILogger logger = null)
        {
            settings = settings ?? new XhtmlMinificationSettings();

            _genericHtmlMinifier = new GenericHtmlMinifier(
                new GenericHtmlMinificationSettings
            {
                WhitespaceMinificationMode              = settings.WhitespaceMinificationMode,
                RemoveHtmlComments                      = settings.RemoveHtmlComments,
                RemoveHtmlCommentsFromScriptsAndStyles  = settings.RemoveHtmlCommentsFromScriptsAndStyles,
                RemoveCdataSectionsFromScriptsAndStyles = false,
                UseShortDoctype    = settings.UseShortDoctype,
                UseMetaCharsetTag  = settings.UseMetaCharsetTag,
                EmptyTagRenderMode = settings.RenderEmptyTagsWithSpace ?
                                     HtmlEmptyTagRenderMode.SpaceAndSlash : HtmlEmptyTagRenderMode.Slash,
                RemoveOptionalEndTags             = false,
                RemoveTagsWithoutContent          = settings.RemoveTagsWithoutContent,
                CollapseBooleanAttributes         = false,
                RemoveEmptyAttributes             = settings.RemoveEmptyAttributes,
                AttributeQuotesRemovalMode        = HtmlAttributeQuotesRemovalMode.KeepQuotes,
                RemoveRedundantAttributes         = settings.RemoveRedundantAttributes,
                RemoveJsTypeAttributes            = false,
                RemoveCssTypeAttributes           = false,
                RemoveHttpProtocolFromAttributes  = settings.RemoveHttpProtocolFromAttributes,
                RemoveHttpsProtocolFromAttributes = settings.RemoveHttpsProtocolFromAttributes,
                RemoveJsProtocolFromAttributes    = settings.RemoveJsProtocolFromAttributes,
                MinifyEmbeddedCssCode             = settings.MinifyEmbeddedCssCode,
                MinifyInlineCssCode              = settings.MinifyInlineCssCode,
                MinifyEmbeddedJsCode             = settings.MinifyEmbeddedJsCode,
                MinifyInlineJsCode               = settings.MinifyInlineJsCode,
                ProcessableScriptTypeList        = settings.ProcessableScriptTypeList,
                MinifyKnockoutBindingExpressions = settings.MinifyKnockoutBindingExpressions,
                MinifyAngularBindingExpressions  = settings.MinifyAngularBindingExpressions,
                CustomAngularDirectiveList       = settings.CustomAngularDirectiveList,
                UseXhtmlSyntax = true
            },
                cssMinifier,
                jsMinifier,
                logger
                );
        }
示例#8
0
        public static void Configure(WebMarkupMinConfiguration configuration)
        {
            configuration.AllowMinificationInDebugMode = true;
            configuration.AllowCompressionInDebugMode  = true;

            DefaultLogger.Current             = new ThrowExceptionLogger();
            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;

            IHttpCompressionManager httpCompressionManager = HttpCompressionManager.Current;

            httpCompressionManager.CompressorFactories = new List <ICompressorFactory>
            {
                new BrotliCompressorFactory(new BrotliCompressionSettings
                {
                    Level = 1
                }),
                new DeflateCompressorFactory(new DeflateCompressionSettings
                {
                    Level = CompressionLevel.Fastest
                }),
                new GZipCompressorFactory(new GZipCompressionSettings
                {
                    Level = CompressionLevel.Fastest
                })
            };
        }
        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;
        }
示例#10
0
        // 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>();
        }
示例#11
0
 /// <summary>
 /// Minifies the XHTML 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 MinifyXhtml(bool useEmptyMinificationSettings = false)
 {
     // https://github.com/Taritsyn/WebMarkupMin/wiki/XHTML-Minifier
     _minificationSettings = new XhtmlMinificationSettings(useEmptyMinificationSettings);
 }
示例#12
0
        // 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>();
        }
示例#13
0
        // 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>();
        }
示例#14
0
        // 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");
                //}));
            });
        }