Page 1 of 1

Combining .js - HELP

Posted: Sun Aug 12, 2018 1:05 am
by ideep13
Hi,

I am trying to combine 5 external .js into 1 .js named defer.js

I really don't get it what I am doing wrong..

This are external .js:

https://xx.com/journal-cache/_b88d0ea5b ... 6642eee.js

https://platform-api.sharethis.com/js/s ... iance-tool

https://xx.com/journal-cache/_b7bb2e4eb ... a4cc761.js

https://cc.cdn.civiccomputing.com/8.0/c ... 8.0.min.js

https://xx.com/cdn-cgi/apps/head/8MWZuj ... fH3l-iM.js

https://xx.com/cdn-cgi/scripts/5c5dd728 ... ode.min.js

So I created 1 .js named defer.js that starts with <script> and ends with </script> and put all those 5 scripts into one.. with 1 enter space for each .js


than I added this code under footer.tpl before </body> ends..

Code: Select all

<script type="text/javascript">
function downloadJSAtOnload() {
var element = document.createElement("script");
element.src = "defer.js";
document.body.appendChild(element);
}
if (window.addEventListener)
window.addEventListener("load", downloadJSAtOnload, false);
else if (window.attachEvent)
window.attachEvent("onload", downloadJSAtOnload);
else window.onload = downloadJSAtOnload;
</script>
and it doesn't work..?

Can please someone help me with this? I would really appreciate it.

I tried to follow this instructions but doesn't work https://varvy.com/pagespeed/defer-loadi ... cript.html

I am using OC 2.3.0.2. HELP!

Re: Combining .js - HELP

Posted: Sun Aug 12, 2018 8:59 am
by rjcalifornia
ideep13 wrote:
Sun Aug 12, 2018 1:05 am
Hi,

I am trying to combine 5 external .js into 1 .js named defer.js

I really don't get it what I am doing wrong..

This are external .js:

https://staskka.com/journal-cache/_b88d ... 6642eee.js

https://platform-api.sharethis.com/js/s ... iance-tool

https://staskka.com/journal-cache/_b7bb ... a4cc761.js

https://cc.cdn.civiccomputing.com/8.0/c ... 8.0.min.js

https://staskka.com/cdn-cgi/apps/head/8 ... fH3l-iM.js

https://staskka.com/cdn-cgi/scripts/5c5 ... ode.min.js

So I created 1 .js named defer.js that starts with <script> and ends with </script> and put all those 5 scripts into one.. with 1 enter space for each .js


than I added this code under footer.tpl before </body> ends..

Code: Select all

<script type="text/javascript">
function downloadJSAtOnload() {
var element = document.createElement("script");
element.src = "defer.js";
document.body.appendChild(element);
}
if (window.addEventListener)
window.addEventListener("load", downloadJSAtOnload, false);
else if (window.attachEvent)
window.attachEvent("onload", downloadJSAtOnload);
else window.onload = downloadJSAtOnload;
</script>
and it doesn't work..?

Can please someone help me with this? I would really appreciate it.

I tried to follow this instructions but doesn't work https://varvy.com/pagespeed/defer-loadi ... cript.html

I am using OC 2.3.0.2. HELP!
[/quote

I suggest not to do that. You will face several problems, such as:

Possible conflicting libraries (Date.prototype.toJSON() is often defined in libs)
More documentation to keep track of
More code to keep updated and secure
More time spent figuring out which library you want to use for what.