Use static resource compression to consolidate static resource files reduce the number of client requests, compress file sizes, and reduce network traffic loss
Need to use Microsoft ASP. NET Web Optimization, installation method:
Install-package Microsoft.AspNet.Web.Optimization
Refer to the MVC architecture method, add BundleConfig.cs in App_start
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;usingSystem.Web.Optimization;namespaceemptywebform{ Public classBundleconfig { Public Static voidregisterbundles (bundlecollection bundles) {bundles. ADD (NewScriptbundle ("~/bundles/jquery"). Include ("~/scripts/jquery-{version}.js")); Bundles. ADD (NewScriptbundle ("~/bundles/jqueryui"). Include ("~/scripts/jquery-ui-{version}.js")); Bundles. ADD (NewScriptbundle ("~/bundles/jqueryval"). Include ("~/scripts/jquery.unobtrusive*", "~/scripts/jquery.validate*")); Bundles. ADD (NewScriptbundle ("~/bundles/webformsjs"). Include ("~/scripts/webforms/webforms.js", "~/scripts/webforms/webuivalidation.js", "~/scripts/webforms/menustandards.js", "~/scripts/webforms/focus.js", "~/scripts/webforms/gridview.js", "~/scripts/webforms/detailsview.js", "~/scripts/webforms/treeview.js", "~/scripts/webforms/webparts.js")); Bundles. ADD (NewScriptbundle ("~/BUNDLES/MSAJAXJS"). Include ("~/scripts/webforms/msajax/microsoftajax.js", "~/scripts/webforms/msajax/microsoftajaxapplicationservices.js", "~/scripts/webforms/msajax/microsoftajaxtimer.js", "~/scripts/webforms/msajax/microsoftajaxwebforms.js")); Bundles. ADD (NewScriptbundle ("~/bundles/modernizr"). Include ("~/scripts/modernizr-*")); Bundles. ADD (NewStylebundle ("~/bundles/themes/base/style"). Include ("~/content/themes/base/style*")); } }}
Add Style1.css and Style2.css as tests under themes
1{2border:solid 1px red3 }
Style1.css
1{2color:red3 }
Style2.css
Modify the page to apply CSS and JS method as follows:
<%@ Page Language="C #"AutoEventWireup="true"codebehind="Index.aspx.cs"Inherits="Emptywebform.index" %><!DOCTYPE HTML><HTMLxmlns= "http://www.w3.org/1999/xhtml"><Headrunat= "Server"><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"/> <title></title> <%: System.Web.Optimization.Scripts.Render ("~/bundles/jquery") %> <%: System.Web.Optimization.Scripts.Render ("~/bundles/webformsjs")%> <%: System.Web.Optimization.Styles.Render ("~/bundles/themes/base/style")%> </Head><Body> <formID= "Form1"runat= "Server"> <Div> </Div> </form></Body></HTML>
In the results of the page request, the compressed files are automatically merged according to the configuration, as detailed below:
The CSS compression effect is as follows, two style sheet files are merged into one and compressed
Reference:
https://blogs.msdn.microsoft.com/rickandy/2012/08/14/adding-bundling-and-minification-to-web-forms/
Use Microsoft ASP. NET WebForm to compress JS and CSS in ASP. WEB optimization