Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

JavaScript Compression Problem

Posted on 2014-01-08
2
Medium Priority
?
224 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to implement server side field validation and display customized error messages to the client.
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 how to count occurrences of each item in an array.

715 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