Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > External JavaScript showing up as inline after reload?

External JavaScript showing up as inline after reload?
Thread Tools
Oisín
Moderator Emeritus
Join Date: Mar 2004
Location: Copenhagen
Status: Offline
Reply With Quote
Mar 5, 2011, 10:40 AM
 
I have quite a simple page where I include a .js JavaScript. My include code is very straightforward:
code:
<script type="text/javascript" src="scripts.js"></script>


The above code is what I would expect to show up when viewing the source code of the final HTML page in the browser.

And it does. Once.

If I reload the page or click on a link and come back to the page, it’s changed to (completely correct, with CDATA entries and all) inline JavaScript in the source code instead, like so:
code:
<script type="text/javascript">//<![CDATA[
function yadaYada {
[stuff here]
}
//]]></script>


Not that this is really a big deal, but does anyone have any logical explanation for why this is happening? I’ve Googled it and can’t find any documentation of this behaviour anywhere. It kind of bugs me a bit, ’cause I think inline JavaScript in HTML files looks ugly. I don’t even know if this is taking place on the server or in the browser.

Edit: Also possibly related: all my carefully balanced tabs and indents in the source code are gone, too.
( Last edited by Oisín; Mar 5, 2011 at 11:01 AM. )
     
Oisín  (op)
Moderator Emeritus
Join Date: Mar 2004
Location: Copenhagen
Status: Offline
Reply With Quote
Mar 5, 2011, 12:37 PM
 
Just happened to come across the explanation here, while looking at another weirdness that had just cropped up:

I noticed that changes to my CSS file weren’t reflected in the page being served. Very odd. Checking the source, I noticed that the style sheet URL being used wasn’t the same as the one defined in the document. Even odder.

Turns out I had at some point apparently enabled Google Pagespeed for this domain. Turning that off fixed everything. Inlining JavaScript, removing indents, and replacing CSS files with cached versions is apparently part and parcel of Pagespeed’s effect.
     
   
Thread Tools
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 03:29 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,