JS Print Button - Problem with Async as it calls External Script.

Job ID: 32622994

Budget: $30 – $250 USD

Our website uses a JS script on the main page.

This specific JS script is called a different way as it provides info for the print service.

The main calls this script like this.
<script async type="text/javascript">
(function() {
var p=document.createElement("script");p.type="text/javascript";p.async=true;
var h=("https:"==document.location.protocol?"https://":"http://");
p.src=h+"www.websitename.com/waitme/14626967972658667.js";
var s=document.getElementsByTagName("script")[0];s.parentNode.insertBefore(p,s);
}).call(this);
script.async = 'async';
</script>

Which in theory should load async, but does not.

The headers of that page loads another external script like this

var timestamp = "03-03-2019 18:24";
var checkoutUrl = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'secure.print.peecho.com/button';
var baseAssetUrl = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'd2pbvzqv6ybw6u.cloudfront.net';

if (!window.JSON) {
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = baseAssetUrl + '/storage/javascript/json2.js';
head.appendChild(script);
}

So... IDEAL FIX Is...

index.html calls both of the 2 external scripts... locally instead and async

I have copied these to
/waitme/14626967972658667.js
/waitme/14626967972658667.js

Can these also be merged into one script instead of one calling the other?

also ideally

only have the main page button call that script.... When the button is clicked, Not Everytime the page loads.

a fantastic review will be given if you can get it to load async,
Or not at all if it is called when the button is clicked... even better.
Related categories: PHP JavaScript jQuery / Prototype Node.js