merge multiple js files into one

to mininmize number of request to the server
This commit is contained in:
moneroexamples 2018-02-01 11:51:37 +08:00
parent 92441758fe
commit d3120c73dc
3 changed files with 39 additions and 19 deletions

View File

@ -549,6 +549,22 @@ main(int ac, const char* av[])
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;
});
}

View File

@ -294,7 +294,7 @@ namespace xmreg
string mainnet_url;
string js_html_files;
string js_html_files_all_in_one;
// instead of constatnly reading template files
// from hard drive for each request, we can read
@ -391,28 +391,29 @@ namespace xmreg
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");
if (enable_js)
{
if (enable_js) {
// JavaScript files
template_file["jquery.min.js"] = xmreg::read(JS_JQUERY);
template_file["crc32.js"] = xmreg::read(JS_CRC32);
template_file["crypto.js"] = xmreg::read(JS_CRYPTO);
template_file["cn_util.js"] = xmreg::read(JS_CNUTIL);
template_file["base58.js"] = xmreg::read(JS_BASE58);
template_file["jquery.min.js"] = xmreg::read(JS_JQUERY);
template_file["crc32.js"] = xmreg::read(JS_CRC32);
template_file["crypto.js"] = xmreg::read(JS_CRYPTO);
template_file["cn_util.js"] = xmreg::read(JS_CNUTIL);
template_file["base58.js"] = xmreg::read(JS_BASE58);
template_file["nacl-fast-cn.js"] = xmreg::read(JS_NACLFAST);
template_file["sha3.js"] = xmreg::read(JS_SHA3);
template_file["config.js"] = xmreg::read(JS_CONFIG);
template_file["biginteger.js"] = xmreg::read(JS_BIGINT);
template_file["sha3.js"] = xmreg::read(JS_SHA3);
template_file["config.js"] = xmreg::read(JS_CONFIG);
template_file["biginteger.js"] = xmreg::read(JS_BIGINT);
// need to set "testnet: false," flag to reflect
// if we are running testnet or mainnet explorer
if (testnet)
{
template_file["config.js"] = std::regex_replace(
template_file["config.js"],
std::regex("testnet: false"),
"testnet: true" );
template_file["config.js"],
std::regex("testnet: false"),
"testnet: true");
}
js_html_files += "<script src=\"/js/jquery.min.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/cn_util.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)
{
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;
}};
}

View File

@ -95,8 +95,8 @@
</h5>
<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="text" name="xmr_address" size="90" placeholder="Monero address/subaddress"><br/>
<input type="text" name="viewkey" size="90" placeholder="Private viewkey" style="margin-top:5px"><br/>
<input type="text" name="xmr_address" size="120" placeholder="Monero address/subaddress"><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}}">
<!--above raw_tx_data field only used when checking raw tx data through tx pusher-->
@ -131,10 +131,10 @@
</h5>
<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="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}}">
<!--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}}
<!-- if have js, DONOT submit the form to server.