Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

Using CDN for jQuery

edited February 2011 in Vanilla 2.0 - 2.8
Make AddJsFile method in library\core\class.controller.php to look as follows:

public function AddJsFile($FileName, $AppFolder = '') { if ($FileName == 'jquery.js') { $FileName = 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js'; } $this->_JsFiles[] = array('FileName' => $FileName, 'AppFolder' => $AppFolder); }

This approach allow to load JQuery library from nearest Google server, speeding up loading.

Overall, if you installed many plugins your loading process mecome much more slow with many CSS and JS files.
Integrating some plugins into core scripts and styles (I mean Tagging Enchanced, Voting and few others) could help slightly.
«1

Comments

  • Options
    thanks!
  • Options
    edited February 2011
    I added this info with details to
    http://www.vanilla-wiki.info/Libraries/CDN
  • Options
    LincLinc Detroit Admin
    A better way would be a plugin that uses Base_Render_Before to 'RemoveJs' the existing jQuery files and then AddJs the CDN ones.
  • Options
    edited February 2011
    May be.
    But using plugins for such low level and small things seems inappropriate, much better to have special checkbox on some settings form that writes value to config file. And all functionality will be present by default. I think it is better.
    Plugins are sometimes overused in Vanilla.

  • Options
    LincLinc Detroit Admin
    On the contrary, I think that would be much worse.
  • Options
    edited February 2011
    Any reasons?
    I think that approach used by most forums considering admin settings is more appropriate than current one in Vanilla where many settings can be only set via manual config editing. May be make Advanced settings page, but we need this.
    And making plugin for two lines that must be on every large site using jQuery by default? Are you serious?
  • Options
    LincLinc Detroit Admin
    edited February 2011
    Great Software becomes Terrible Software by adding "one more option." It's the death by 1000 checkboxes, and yes, I'm completely serious.

    By adding the "Use CDN for jQuery?" checkbox, now every Vanilla user from now until time untold needs to decide whether to check it, and maybe get confused about what CDN and jQuery are, or decide to ignore it. That cost them time. However, someone like you who knows what a CDN is can easily find the Addons repo and find a simple little plugin that does that esoteric thing you want.

    Making great software isn't just adding more, it's about deciding what to leave out.
  • Options
    I do not agree here.
    being UX designer, I can say that this common "more is worse" thing is fallancy and a bad one.
    No one prevents you to hide advanced options using good interface form novice users.
    But gently speaking I know not so much novice users who run average or big sized forums. And all options that are not required on small forums can be hidden in special section.
    Moving such functions to addons makes them hard to support and hard to change.
    Looking at state of Addons section I can say that this is very bad idea then people can find even old long unsuported plugins that can even break his forums for some time.
  • Options
    SS ✭✭
    Imposible to replace local jquery.js by CDN jquery.js using Base_Render_Before, because jquery must included before any jquery plugin. AddJsFile() method adds file to the end of collection _JsFiles.

    Need use `HeadModule_BeforeToString_Handler($Head)`
    Or add new event EventArguments/BeforeAddJs like BeforeAddCss in Gdn_Controller.
  • Options
    SS ✭✭
    I agree that is job for plugin.
  • Options
    SS ✭✭
    edited February 2011
    Just added to my themehooks
    public function HeadModule_BeforeToString_Handler($Head) {
    if (Gdn_Statistics::IsLocalhost()) return; // not for localhost
    $Tags = $Head->Tags();
    foreach ($Tags as &$Tag) {
    if ($Tag['_tag'] != 'script') continue;
    $Path = parse_url($Tag['src'], PHP_URL_PATH);
    if (strpos($Tag['src'], '//') === False && pathinfo($Path, PATHINFO_BASENAME) == 'jquery.js') {
    $Tag['src'] = 'http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js';
    break;
    }
    }
    $Head->Tags($Tags);
    }
  • Options
    LincLinc Detroit Admin
    Good tip, thanks @S.
  • Options
    SS ✭✭
    edited February 2011
    I have plans to write a plugin that will do some optimizations that recommends Google.
    Combine external CSS
    Combine external JavaScript
    Enable compression
    Leverage browser caching
    Minify CSS
    Minify JavaScript
    Parallelize downloads across hostnames
    Avoid CSS @import
    `Minify` doesnt work for me and looks buggy.
  • Options
    edited February 2011
    What you mean under combining CSS?
    If you'll be always combining CSS, it won't be good. As caching won't work properly.
    Minify CSS or JS is also not so usable, if web server use gzip (and it is so in most cases) :-)
    This optimizations are fine for abstract static pages or simple cms with one style, but for engines like Vanilla approach must be pretty manual and smart. This is why original Minify plugin idea is not so good.

    Generally only parts that need to be optimized are discussions list, discussion list and categories list. And 90% of optimizations on client side lie in merging Gravatar, Voting, Tagging and few other plugins, their JS and styles.

  • Options
    SS ✭✭
    edited February 2011
    If you'll be always combining CSS, it won't be good. 
    I understand that.

    I have no apache/mod_gzip/mod_deflate.

    My statistics by YSlow for news page.
    HTTP Requests - 52
    Total Weight - 284.5K
    1 HTML/Text 23.2K
    9 JavaScript File 69.0K
    20 Stylesheet File 82.4K
    15 CSS Image 59.9K
    5 Image 47.6K
    1 Favicon 0.2K
    1 XMLHttpRequest 1.9K
    9 JavaScript File, 20 Stylesheet File, not bad, ha?
  • Options
    Good optimier must be special plugin that scans (one time only, after installation of all required plugins) all enabled plugins for AddCSSFile and AddJSFile, analize dependencies, combine files and minify them, change corresponding plugins lines commenting all old methods calls and adding new, changing files names to new ones. This is real optimization, saving server time also.
  • Options
    LincLinc Detroit Admin
    I think I fixed Minify on unstable. It was choking on subfolder installs but I think I got to the bottom of it.
  • Options
    edited February 2011
    @Lincoln, can you provide more details of Minify inner workings?
    My understanding is that it just looks for tags, and combines JS and CSS files and supply these two files instead of bunch of CSS and JS?
    And do it on the fly on each request?
    Looks like it is using some kind of cache.
  • Options
    LincLinc Detroit Admin
    Yup, it combines all CSS files into 1 minified file and all JS into 2 minified files (1 of global jquery stuff and 1 of per-page/plugin stuff). It uses a cache, so it's only generating those files if a new combination is requested. It clears the cache whenever apps/plugins/themes are enabled or disabled.
Sign In or Register to comment.