我有一些代码可以生成一个HTML文件,但是,如果有很多文本,文件会远远高于50MB,有时会达到70-80MB。减少HTML文件大小?
我不希望有一个HTML文件达到这个尺寸是诚实的。这是定义HTML模板的源代码。
namespace Structure
{
const std::string strHTMLTemplate = "<doctype html>"
"<html lang=\"en\">"
"<head>"
"<meta charset=\"utf-8\"/>"
"<title>Data Verifier Test Results - {@testdesc}</title>"
"<style>"
"body {"
"\tbackground: none repeat scroll 0 0 #F3F3F4;"
"\tcolor: #1E1E1F;"
"\tfont-family: \"Segoe UI\",Tahoma,Geneva,Verdana,sans-serif;"
"\tmargin: 0;"
"\tpadding: 0;"
"}"
"h1 {"
"\tbackground-color: #E2E2E2;"
"\tborder-bottom: 1px solid #C1C1C2;"
"\tcolor: #201F20;"
"\tfont-size: 24pt;"
"\tfont-weight: normal;"
"\tmargin: 0;"
"\tpadding: 10px 0 10px 10px;"
"}"
"h2 {"
"\tfont-size: 21pt;"
"\tfont-weight: normal;"
"\tmargin: 0;"
"\tpadding: 15px 0 5px;"
"}"
"h3 {"
"\tbackground-color: rgba(0, 0, 0, 0);"
"\tfont-size: 18pt;"
"\tfont-weight: normal;"
"\tmargin: 0;"
"\tpadding: 15px 0 5px;"
"}"
"h4 {"
"\tbackground-color: rgba(0, 0, 0, 0);"
"\tfont-size: 15pt;"
"\tfont-weight: normal;"
"\tmargin: 0;"
"\tpadding: 15px 0 5px;"
"}"
"h5 {"
"\tbackground-color: rgba(0, 0, 0, 0);"
"\tfont-size: 12pt;"
"\tfont-weight: normal;"
"\tmargin: 0;"
"\tpadding: 15px 0 5px;"
"}"
"a {"
"\tcolor: #1382CE;"
"}"
"table {"
"\tborder-collapse: collapse;"
"\tborder-spacing: 0;"
"\tfont-size: 8pt;"
"}"
"table th {"
"\tbackground: none repeat scroll 0 0 #E7E7E8;"
"\tfont-weight: normal;"
"\tpadding: 1px 2px;"
"\ttext-align: left;"
"\ttext-decoration: none;"
"}"
"table td {"
"\tbackground: none repeat scroll 0 0 #F7F7F8;"
"\tborder: 1px solid #E7E7E8;"
"\tmargin: 0;"
"\tpadding: 1px 2px 1px 1px;"
"\tvertical-align: top;"
"}"
""
".textCentered {"
"\ttext-align: center;"
"}"
".messageCell {"
"\twidth: 100;"
"}"
"#content {"
"\tpadding: 0 12px 12px;"
"}"
"#overview table {"
"\tmax-width: 75;"
"\twidth: auto;"
"}"
"#messages table {"
"\twidth: 97;"
"}"
"</style>"
"</head>"
"<body>"
"<div id=\"big_wrapper\">"
"\t<h1>Test Results - {@testdesc}</h1>"
"\t"
"{@eeddata}"
"\t"
"</body>"
"</html>";
const std::string strHTMLEEDDataEntireMsgTemplate = "\t"
"\t\t<h2 _locID=\"EEDInfo\">{@indveeddata}</h2>"
"{@clientdata}"
"\t";
const std::string strHTMLEEDDataTemplate = "\t"
"{@clientdata}"
"\t";
const std::string strHTMLRequestTemplate = "\t\t<h2 _locID=\"ReqInfo\">Request Information</h2>"
"\t\t<div id=\"ReqInfoResults\">"
"\t\t</div>"
"\t\t<div id=\"ReqValueResults\">"
"\t\t<h3 _locID=\"RequestDataTitle\">Request Data</h3>"
"\t\t\t<table>"
"{@requestbody}"
"\t\t\t</table>"
"\t\t</div>";
const std::string strHTMLResponseTemplate = "\t\t<h2 _locID=\"ResponseTitle\">Response Results</h2>"
"\t\t<div id=\"RespInfoResults\">"
"\t\t</div>"
"\t\t<div id=\"RespValueResults\">"
"\t\t<h3 _locID=\"ResponseDataTitle\">Response Data</h3>"
"\t\t\t<table>"
"{@responsebody}"
"\t\t\t</table>"
"\t\t</div>";
const std::string strHTMLSingleMessageTemplate = "\t\t<h4 _locID=\"MessageTitle\">RWF Message</h4>"
"\t\t<div id=\"MessageResults\">"
"\t\t<h5 _locID=\"ActualMessageResults\">Source: {@source} Destination: {@destination} Timestamp: {@timestamp}</h5>"
"{@messagebody}"
"\t\t</div>";
const std::string strHTMLClientDataTemplate = "\t\t<h3 _locID=\"Client ID: \">{@clientid} {@subclientid}</h3>"
"{@requestmsg}"
"{@responsemsg}";
const std::string strHTMLResponseHdrTemplate = "<tr>"
"<th></th>"
"<th _locID=\"TypeHeader\">Type</th>"
"<th _locID=\"ValueHeader\">Value</th>"
"</tr>"
"<tr>"
"<td style=\"background: blue\"></td>"
"<td><strong>Path</strong></td>"
"<td>{@url}</td>"
"</tr>"
"<tr>"
"<td style=\"background: blue\"></td>"
"<td><strong>IP Address</strong></td>"
"<td>{@iptosendto}</td>"
"</tr>";
const std::string strHTMLReqHdrRowTemplate = "<tr>"
"<th></th>"
"{@reqhdrrowvalue}"
"</tr>";
const std::string strHTMLRespHdrRowTemplate = "<tr>"
"<th></th>"
"{@resphdrrowvalue}"
"</tr>";
const std::string strHTMLReqHdrRowValueTemplate = "<th _locID=\"{@requestvaluehdr}Header\"><strong>{@requestvaluehdr}<strong></th>";
const std::string strHTMLRespHdrRowValueTemplate = "<th _locID=\"{@responsevaluehdr}Header\"><strong>{@responsevaluehdr}<strong></th>";
const std::string strHTMLReqDataRowTemplate = "<tr>"
"<td style=\"background: blue\"></td>"
"{@reqdatarowvalue}"
"</tr>";
const std::string strHTMLRespDataRowTemplate = "<tr>"
"<td style=\"background: blue\"></td>"
"{@respdatarowvalue}"
"</tr>";
const std::string strHTMLRespDataRowValueTemplate = "<td>{@responsevalue}</td>";
const std::string strHTMLReqDataRowValueTemplate = "<td>{@requestvalue}</td>";
const std::string strHTMLCLIENTDATA = "{@clientdata}";
const std::string strHTMLEEDSDATA = "{@eeddata}";
const std::string strHTMLINDVEEDDATA = "{@indveeddata}";
const std::string strHTMLCLIENTID = "{@clientid}";
const std::string strHTMLSUBCLIENTID = "{@subclientid}";
const std::string strHTMLSOURCEIP = "{@source}";
const std::string strHTMLDESTINATIONIP = "{@destination}";
const std::string strHTMLTIMESTAMP = "{@timestamp}";
const std::string strHTMLREQUESTMSG = "{@requestmsg}";
const std::string strHTMLRESPONSEMSG = "{@responsemsg}";
const std::string strHTMLREQUESTBODY = "{@requestbody}";
const std::string strHTMLRESPONSEBODY = "{@responsebody}";
const std::string strHTMLMESSAGEBODY = "{@messagebody}";
const std::string strHTMLREQHDRROWVALUE = "{@reqhdrrowvalue}";
const std::string strHTMLRESPHDRROWVALUE = "{@resphdrrowvalue}";
const std::string strHTMLREQUESTHDR = "{@requesthdr}";
const std::string strHTMLRESPONSEHDR = "{@responsehdr}";
const std::string strHTMLREQUESTVALUEHDR = "{@requestvaluehdr}";
const std::string strHTMLRESPONSEVALUEHDR = "{@responsevaluehdr}";
const std::string strHTMLREQDATAROWVALUE = "{@reqdatarowvalue}";
const std::string strHTMLRESPDATAROWVALUE = "{@respdatarowvalue}";
const std::string strHTMLREQUESTVALUE = "{@requestvalue}";
const std::string strHTMLRESPONSEVALUE = "{@responsevalue}";
const std::string strHTMLTESTDESCRIPTION = "{@testdesc}";
}
有超过1000调用,使用strHTMLReqDataRowTemplate和strHTMLRespDataRowTemplate并提供必要的数据替换{@}标签。这一切都是递归完成的。
看看HTML和CSS,你们能看到我能改善输出的任何方式吗?
HTML页面应该有行和列的数据,而且我经常创建一个包含行和列的表。
你不能“调用”一个变量。你所看到的不是实际的代码。无论如何,一块实际的HTML文件会更好。 (但是不希望有太大的改进,HTML不是一个可以尽可能降低质量的图像,它是文本。) – deviantfan
重写它。谢谢。 –
看看文本内容,在我看来''HTML/CSS'只是替代'> 50mb'后的引用输出大小的一小部分。所以我不认为减少HTML/CSS会给你带来什么是诚实的。与*速度*更相关的可能是你如何*替代*文本。我会编写一个预处理程序来将文本分割为*替换标记*,并将替换文本与* sliced *文本交错发送。 – Galik