In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces the method of "compressing aspx pages to delete excess spaces". In daily operation, I believe that many people have doubts about the methods of deleting excess spaces on compressed aspx pages. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the doubts of "compressing aspx pages to delete excess spaces". Next, please follow the editor to study!
There are two ways to implement:
1) read the aspx file one by one and then process the
2) read the aspx file at once and then process it
Processing logic:
Replace "yes" (replace two spaces with one space) and replace all newline characters with empty characters (extreme compression)
Note:
1) Line-by-line processing requires additional handling of server-side control line wrapping in the case of extreme compression, such as
The copy code is as follows:
Line 1:
In this case, there will be problems in dealing with one line at a time.
2) in addition, inline single-line comments in the JS script
It is recommended to use "/ * /" instead of "/ /"
Results of use:
Line-by-line processing is slightly faster than one-time processing, and for aspx files with two or three hundred lines, the gap is at the millisecond level. However, when dealing with the entire project, the gap should be reflected as the number of documents increases.
One-time read processing can be done without extreme compression, so server controls and inline single-line comments can be ignored.
I rarely use inline comments and single-line comments as well as server controls, so the compression effect is very obvious. Generally, the source code of 500,600 lines is compressed less than 50 lines, and the size is reduced by about 1/3.
However, this compression effect may have a lot to do with whether you use server-side data list controls and how to use them. I usually only use repeater.
The copy code is as follows:
Public static String Replace (String source,String oldStr,String newStr)
{
Int count = Regex.Matches (source, oldStr) .Count
For (int I = 0; I
< count; i++) { source = source.Replace(oldStr, newStr); } return source; } /// /// 压缩指定路径的文件空白字符串和换行符 /// 压缩说明 /// 1)采取File.ReadAllLines读取所有行每一行做处理工作 /// 2)服务器控件最好写在一行内,只做了尾部标签与runat="server"跨行的处理,开始标签跨行为处理 /// 3)文件不能有单行注释"//" /// 4)替换掉了换行符和空格 /// /// 文件路径 public static void CompressLineByLine(String filePath) { if (!File.Exists(filePath)) { Console.WriteLine("文件不存在,检查路径{0}", filePath); return; } var start = DateTime.Now; Console.WriteLine("正在压缩文件:{0}\r\n开始于{1}...", filePath,start.ToString()); var lines = File.ReadAllLines(filePath, Encoding.GetEncoding("GB2312")); for (int i = 0; i < lines.Length; i++) { var item = lines[i].Trim(); if (item.IndexOf("runat=\"server\"") >-1)
Item + = ""
Item = item.Replace ("\ r\ n", "")
Item = Replace (item, ",")
Lines [I] = item
}
File.WriteAllText (filePath, string.Join (", lines))
Encoding.GetEncoding ("GB2312"))
Var end = DateTime.Now
Console.WriteLine ("ends with {0}...", end.ToString ())
Console.WriteLine ("= = time-consuming =\ r\ n {0}\ r\ n", end-start)
}
/ / /
/ / compress the file blank string and newline character of the specified path
/ / Compression description
/ 1) read all the text at once and replace line breaks and whitespace
/ 2) there is no need to deal with the problem of server control line wrapping
/ 3) the compression is not complete. There may still be a space between the closing tag of element An and the opening tag of element B.
/ / /
/ / /
Public static void CompressAtOneTime (String filePath)
{
Var start = DateTime.Now
Console.WriteLine ("compressing files: {0}\ r\ nstarts with {1}...", filePath
Start.ToString ()
Var lines = File.ReadAllText (filePath)
File.WriteAllText (filePath, Replace (Replace (lines, "\ r\ n")
"),", "), Encoding.GetEncoding (" GB2312 ")
Var end = DateTime.Now
Console.WriteLine ("ends with {0}...", end.ToString ())
Console.WriteLine ("= = time-consuming =\ r\ n {0}\ r\ n", end-start)
}
At this point, the study on "the method of compressing aspx pages to delete extra spaces" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.