merge multiple js files into one

to mininmize number of request to the server
master
moneroexamples 7 years ago
parent 92441758fe
commit d3120c73dc

@ -549,6 +549,22 @@ main(int ac, const char* av[])
return xmrblocks.get_js_file("sha3.js"); return xmrblocks.get_js_file("sha3.js");
}); });
CROW_ROUTE(app, "/js/all_in_one.js")
([&](const crow::request& req) {
string all_in_one = xmrblocks.get_js_file("jquery.min.js") +
xmrblocks.get_js_file("crc32.js") +
xmrblocks.get_js_file("biginteger.js") +
xmrblocks.get_js_file("config.js") +
xmrblocks.get_js_file("nacl-fast-cn.js") +
xmrblocks.get_js_file("crypto.js") +
xmrblocks.get_js_file("base58.js") +
xmrblocks.get_js_file("cn_util.js") +
xmrblocks.get_js_file("sha3.js");
return all_in_one;
});
} }

@ -294,7 +294,7 @@ namespace xmreg
string mainnet_url; string mainnet_url;
string js_html_files; string js_html_files;
string js_html_files_all_in_one;
// instead of constatnly reading template files // instead of constatnly reading template files
// from hard drive for each request, we can read // from hard drive for each request, we can read
@ -391,8 +391,7 @@ namespace xmreg
template_file["tx_table_header"] = xmreg::read(string(TMPL_PARIALS_DIR) + "/tx_table_header.html"); template_file["tx_table_header"] = xmreg::read(string(TMPL_PARIALS_DIR) + "/tx_table_header.html");
template_file["tx_table_row"] = xmreg::read(string(TMPL_PARIALS_DIR) + "/tx_table_row.html"); template_file["tx_table_row"] = xmreg::read(string(TMPL_PARIALS_DIR) + "/tx_table_row.html");
if (enable_js) if (enable_js) {
{
// JavaScript files // JavaScript files
template_file["jquery.min.js"] = xmreg::read(JS_JQUERY); template_file["jquery.min.js"] = xmreg::read(JS_JQUERY);
template_file["crc32.js"] = xmreg::read(JS_CRC32); template_file["crc32.js"] = xmreg::read(JS_CRC32);
@ -409,10 +408,12 @@ namespace xmreg
// if we are running testnet or mainnet explorer // if we are running testnet or mainnet explorer
if (testnet) if (testnet)
{
template_file["config.js"] = std::regex_replace( template_file["config.js"] = std::regex_replace(
template_file["config.js"], template_file["config.js"],
std::regex("testnet: false"), std::regex("testnet: false"),
"testnet: true"); "testnet: true");
}
js_html_files += "<script src=\"/js/jquery.min.js\"></script>"; js_html_files += "<script src=\"/js/jquery.min.js\"></script>";
js_html_files += "<script src=\"/js/crc32.js\"></script>"; js_html_files += "<script src=\"/js/crc32.js\"></script>";
@ -423,6 +424,8 @@ namespace xmreg
js_html_files += "<script src=\"/js/base58.js\"></script>"; js_html_files += "<script src=\"/js/base58.js\"></script>";
js_html_files += "<script src=\"/js/cn_util.js\"></script>"; js_html_files += "<script src=\"/js/cn_util.js\"></script>";
js_html_files += "<script src=\"/js/sha3.js\"></script>"; js_html_files += "<script src=\"/js/sha3.js\"></script>";
js_html_files_all_in_one = "<script src=\"/js/all_in_one.js\"></script>";
} }
} }
@ -6210,7 +6213,8 @@ namespace xmreg
add_js_files(mstch::map& context) add_js_files(mstch::map& context)
{ {
context["js_files"] = mstch::lambda{[&](const std::string& text) -> mstch::node { context["js_files"] = mstch::lambda{[&](const std::string& text) -> mstch::node {
return this->js_html_files; //return this->js_html_files;
return this->js_html_files_all_in_one;
}}; }};
} }

@ -95,8 +95,8 @@
</h5> </h5>
<form action="/myoutputs" method="post" style="width:100%; margin-top:2px" class="style-1"> <form action="/myoutputs" method="post" style="width:100%; margin-top:2px" class="style-1">
<input type="hidden" name="tx_hash" value="{{tx_hash}}"><br/> <input type="hidden" name="tx_hash" value="{{tx_hash}}"><br/>
<input type="text" name="xmr_address" size="90" placeholder="Monero address/subaddress"><br/> <input type="text" name="xmr_address" size="120" placeholder="Monero address/subaddress"><br/>
<input type="text" name="viewkey" size="90" placeholder="Private viewkey" style="margin-top:5px"><br/> <input type="text" name="viewkey" size="120" placeholder="Private viewkey" style="margin-top:5px"><br/>
<input type="hidden" name="raw_tx_data" value="{{raw_tx_data}}"> <input type="hidden" name="raw_tx_data" value="{{raw_tx_data}}">
<!--above raw_tx_data field only used when checking raw tx data through tx pusher--> <!--above raw_tx_data field only used when checking raw tx data through tx pusher-->
@ -131,10 +131,10 @@
</h5> </h5>
<form action="/prove" method="post" style="width:100%;margin-top:2px" class="style-1"> <form action="/prove" method="post" style="width:100%;margin-top:2px" class="style-1">
<input type="hidden" name="txhash" value="{{tx_hash}}"><br/> <input type="hidden" name="txhash" value="{{tx_hash}}"><br/>
<input type="text" name="txprvkey" size="90" placeholder="Tx private key"><br/> <input type="text" name="txprvkey" size="120" placeholder="Tx private key"><br/>
<input type="hidden" name="raw_tx_data" value="{{raw_tx_data}}"> <input type="hidden" name="raw_tx_data" value="{{raw_tx_data}}">
<!--above raw_tx_data field only used when checking raw tx data through tx pusher--> <!--above raw_tx_data field only used when checking raw tx data through tx pusher-->
<input type="text" name="xmraddress" size="90" placeholder="Recipient's monero address/subaddress" style="margin-top:5px"><br/> <input type="text" name="xmraddress" size="120" placeholder="Recipient's monero address/subaddress" style="margin-top:5px"><br/>
{{#enable_js}} {{#enable_js}}
<!-- if have js, DONOT submit the form to server. <!-- if have js, DONOT submit the form to server.

Loading…
Cancel
Save