Embedded JS - caching issues?

James

Well-known member
Most of you have probably noticed the embedded JS in the homepage:
Code:
<script type="text/javascript">
   <!--
   jQuery.extend(true, XenForo,
   {
       serverTimeInfo: { now: 1281053457, today: 1281049200, todayDow: 5 },
       visitor: { user_id: 908 },
       _overlayConfig: { top: '10%', mask: { color: 'white', opacity: 0.6, loadSpeed: 200}}, //TODO: source this from style properties
       _loadedScripts: {"node_list":true,"node_category":true,"node_forum":true,"node_page":true},
       _cookieConfig: { path: "/", domain: "", prefix: "xf_"},
       _csrfRefreshUrl: "login/csrf-token-refresh"
   });

   jQuery.extend(XenForo.phrases,
   {
       a_moment_ago:    "A moment ago",
       one_minute_ago:  "1 minute ago",
       x_minutes_ago:   "%minutes% minutes ago",
       today_at_x:      "Today at %time%",
       yesterday_at_x:  "Yesterday at %time%",
       day_x_at_time_y: "%day% at %time%",

       day0: "Sunday",
       day1: "Monday",
       day2: "Tuesday",
       day3: "Wednesday",
       day4: "Thursday",
       day5: "Friday",
       day6: "Saturday",

       _months: "January,February,March,April,May,June,July,August,September,October,November,December",
       _daysShort: "Sun,Mon,Tue,Wed,Thu,Fri,Sat"
   });

   XenForo.Facebook.appId = '146201428725181';
   //-->
   </script>
Code:
<script type="text/javascript">


   var _gaq = _gaq || [];
   _gaq.push(['_setAccount', 'UA-10855523-4']);
   _gaq.push(['_trackPageview']);

   (function() {
   var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
   ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
   var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
   })();


</script>

Wouldn't that cache better as an external file?
(FYI: I'm not being pedantic, just looking at optimum speeds! ;))
 
I think they're still doing a lot of testing and debugging. Once they're certain they're done the CSS and JS will be minified.

Some of that JS however is using phrases, which I don't think can be done without being embedded.

That last bit isn't used by XF, but by Google Analytics. That is how they specify you should use their code.
 
Yeah I was just picking out the bits of JS that are there. I think the phrases should be alright as external files as long as they're loaded before the JS that manipulates the phrases are loaded?
 
In the first box, the values need to be dynamically written via PHP depending on the viewing users Language/Style. Not possible to do via a static file. (Well... it's possible, but it would mean creating a new file for every language and style installed on a board, then overwriting said file every time a change is made.)

And the bottom... well that's Google Analytics, and I'm sure they have some policy about putting it in an external file or something.
 
In the first box, the values need to be dynamically written via PHP depending on the viewing users Language/Style. Not possible to do via a static file. (Well... it's possible, but it would mean creating a new file for every language and style installed on a board, then overwriting said file every time a change is made.)

And the bottom... well that's Google Analytics, and I'm sure they have some policy about putting it in an external file or something.

You could do it by outputting that Javascript via something like js.php and it could still be cached far into the future by the browser.
 
Maybe, but is it realistic to do so for just ten lines of Javascript?

Well that's not that stupid, it's already what happens when you have CSS as files in vB4.

So the "phrases and css" js variables could be treated like that and rebuild when the admin edit a phrase in the acp or changes a css parameters for example.
 
Well that's not that stupid, it's already what happens when you have CSS as files in vB4.

So the "phrases and css" js variables could be treated like that and rebuild when the admin edit a phrase in the acp or changes a css parameters for example.

There's a difference between 10 lines of Javascript... and hundreds of lines of CSS...

It's realistic to do so for CSS because of how much there is.
 
I was just thinking for efficiency and loading usage :p thanks Mike.

P.S: Are there any plans to move the JS files above the closing body tag (we all know about pages stopping loading when JS is loaded blahblah)?
 
Back
Top Bottom