0

I'm building a large jQuery widget and I have some scripts I depend on to run this widget. Of course I could just include them in my html page but that not so hot. I need to load them from my widget.

I know about $.getScript but unfortunately it seems like it will run the code after the end } before running what is in it. It also does not cache the scripts which will slow are site down.

I've tried the LazyLoad plugin, same deal as $.getScript(), it will run the code after the function before what's in it.

What I'd like to do is in the _create function I could just call this._dependencies() and load all the required scripts I need and then continue in _create.

Here's some code:

;(function ($, window, document, undefined) {
    $.widget("test", {
        create: function () {
            this._dependencies();
            $..setLocale(this.locale);
        },
        _dependencies: functio() {
            LazyLoad.js(['jquery.i18n.js', 'test.i18n.js'], function () {});
        }
    });
})(jQuery, window, document);
Kevin B
  • 94,570
  • 16
  • 163
  • 180
Chris
  • 261
  • 1
  • 4
  • 13
  • We'd need to see code, it appears as though you might be using `$.getScript` in a synchronous manner rather than asynchronous. Also, `$.getScript` by default will allow the browser to do caching. – Kevin B Apr 10 '13 at 19:44
  • ;(function ( $, window, document, undefined ) { $.widget( "test" , { _create: function () { this._dependencies(); $._.setLocale(this.locale); }, _dependencies: functio() { LazyLoad.js([ 'jquery.i18n.js', 'test.i18n.js' ], function() { }); } }); })( jQuery, window, document ); Here's a sample. I have an error at setLocale. sorry don't know how to format the text properly in a comment. – Chris Apr 10 '13 at 20:01
  • 1
    Comment's aren't really meant for that much code, it should be included in your question. – Kevin B Apr 10 '13 at 20:04
  • `$..setLocale` will cause a syntax error in javascript, did you mean `$.setLocale`? – Kevin B Apr 10 '13 at 20:07
  • no that's a plugin, it's $.[underscore].setLocale() – Chris Apr 11 '13 at 12:03
  • I found this: http://stackoverflow.com/questions/11803215/how-to-include-multiple-js-files-using-jquery-getscript-method but how would I include my whole plugin with this code. I've tried only putting the plugin call in there but doesn't work. – Chris Apr 11 '13 at 12:33

0 Answers0