Solved

JavaScript Compression Problem

Posted on 2014-01-08
2
211 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

735 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