1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Embedded JS - caching issues?

Discussion in 'XenForo Pre-Sales Questions' started by James, Aug 6, 2010.

  1. James

    James Well-Known Member

    Most of you have probably noticed the embedded JS in the homepage:
    <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"
           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 type="text/javascript">
       var _gaq = _gaq || [];
       _gaq.push(['_setAccount', 'UA-10855523-4']);
       (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);
    Wouldn't that cache better as an external file?
    (FYI: I'm not being pedantic, just looking at optimum speeds! ;))
  2. Onimua

    Onimua Well-Known Member

    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.
  3. James

    James Well-Known Member

    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?
  4. Ryan Ashbrook

    Ryan Ashbrook Active Member

    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.
  5. Onimua

    Onimua Well-Known Member

    That's how it currently works. Putting it into a file would break that.
  6. MtoR

    MtoR Well-Known Member

    Yeah I agree this is part of the js they can't put into files due to their dynamic characteristics
  7. Enigma

    Enigma Well-Known Member

    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.
    James and Msharry like this.
  8. Ryan Ashbrook

    Ryan Ashbrook Active Member

    Maybe, but is it realistic to do so for just ten lines of Javascript?
  9. Msharry

    Msharry Active Member

  10. MtoR

    MtoR Well-Known Member

    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.
  11. Ryan Ashbrook

    Ryan Ashbrook Active Member

    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.
  12. Mike

    Mike XenForo Developer Staff Member

    It's really not worth the overhead of another request (both server and client side) for such a small amount of data.
  13. James

    James Well-Known Member

    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)?

Share This Page