Link to home
Start Free TrialLog in
Avatar of webstuck5
webstuck5

asked on

JavaScript Compression Problem

I have the following compressed script to load sharethis buttons and a Google search box asynchronously:

  <script> 
      ( function (w, d, load) { var script, first = d.getElementsByTagName('SCRIPT')[0], n = load.length, i = 0, go = function () { for (i = 0; i < n; i = i + 1) { script = d.createElement('SCRIPT'); script.type = 'text/javascript'; script.async = true; script.src = load[i]; first.parentNode.insertBefore(script, first); } } 
      if (w.attachEvent) { w.attachEvent('onload', go); } else { w.addEventListener('load', go, false); } } ( window, document, [ 'http://w.sharethis.com/button/buttons.js', 'http://www.google.com/coop/cse/brand?form=cse-search-box&amp;lang=en' ] ) ); 
  </script>

Open in new window


This works fine and my sharethis buttons load and show up on the page. However, my HTML compressor program actually places the second long script line starting with if (w.attachEvent) up next to the first script line and when it does that, my sharethis buttons don't show up on the page. Why would that be and is there a way that I could edit the JavaScript code so that my compression program wouldn't cause sharethis not to work?
ASKER CERTIFIED SOLUTION
Avatar of Gary
Gary
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of webstuck5
webstuck5

ASKER

I even thought there needs to be a ; somewhere.