Solved

JavaScript Compression Problem

Posted on 2014-01-08
2
204 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
2 Comments
 
LVL 58

Accepted Solution

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

Author Closing Comment

by:webstuck5
Comment Utility
I even thought there needs to be a ; somewhere.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now