Solved

JavaScript Compression Problem

Posted on 2014-01-08
2
218 Views
Last Modified: 2014-01-08
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?
0
Comment
Question by:webstuck5
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 39766475
Add a ; after the first line.
0
 

Author Closing Comment

by:webstuck5
ID: 39766798
I even thought there needs to be a ; somewhere.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question