Closed isaacfreeman closed 11 years ago
I would question why we build jquery into breeze, as opposed to including it from Google, where most users will already have a cached copy. https://developers.google.com/speed/libraries/
There are a few factors to balance (off the top of my head – let me know if I have any of this wrong):
We've taken the approach of serving our own copy of jQuery through the pipeline. A couple of other approaches we could consider...
It's just I notice the jquery website itself uses the Google api
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
I guess from the Google site there's 1 year of caching, whereas the asset pipeline is going to change it every time we change any of the on-site javascript, though presumably that's almost never, and as you say the benefit from an external source is probably negated by the asset pipeline.
Just bringing it up as a question, since we're going to modify it. :)
I've seen people use the google api callback code to ensure specific stuff only loads once jquery has loaded, but I assume it's far too complicated for our uses.
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("jquery", "1.8.3", {"callback" : jqueryLoaded});
google.load("jqueryui", "1.9.2" {"callback" : jqueryuiLoaded});
</script>
So you can hook stuff up to the callbacks
function jqueryLoaded() {
//stuff that should be run now that jquery is loaded
}
The benefit being you can load the page without scripts, and have them load in afterwards. But this obviously doesn't work in the breeze backend. https://developers.google.com/loader/
Closing this one. Instead of documentation, we've gone with a default theme template which people can install at the beginning of a project. This includes the javascript tag for breeze/breeze.
Whether this is the best way to include jQuery is something we could test separately.
Designers building themes are used to adding links to jQuery and other JS libraries. A lot of the time they only need to add
and they'll already have jQuery and jQUery UI.
We need some documentation explaining this, so designers don't load multiple copies of jQuery from different sources. Apart from extra load time, this can cause weird behaviour. For example, when they're using Breeze Commerce, two instances of jQuery means that every Add to Cart action occurs twice.
Designers need to know...