Skip to content
This repository has been archived by the owner on Jul 18, 2023. It is now read-only.

Use jQuery from CDN #14

Open
tsimbalar opened this issue May 17, 2012 · 9 comments
Open

Use jQuery from CDN #14

tsimbalar opened this issue May 17, 2012 · 9 comments
Assignees

Comments

@tsimbalar
Copy link
Member

We should reference the jQuery and jQuery UI libraries from a Content Delivery Network (for instance Google : https://developers.google.com/speed/libraries/devguide ) so that users can benefit from browser caching (they may have those libs in their cache already) and do not impact our server resources unnecessarily.

We should offer a fallback for when we are working locally and offline though : see http://css-tricks.com/snippets/jquery/fallback-for-cdn-hosted-jquery/

For other js libraries that wouldn't be hosted by Google, see : http://www.cdnjs.com/

@benzonico
Copy link
Member

I'll try to give it a look tomorrow, this cdn problem has some interest for me and the fallack is brilliant.

@ghost ghost assigned benzonico May 19, 2012
@benzonico
Copy link
Member

Ok, having a look at this, it seems that the fallback would work nicely for jQuery lib but I have no clue about how to make it work for jquery-ui for example of for the css...
So i am linking this to CDN directly for now. And another thing : M$ and Google are not reactive enough to have integrated the 1.8.20 version to their CDN already so we are using the 1.8.19 version right now (but this is easily upgradable as soon as they have published the last version).

So what I did is that if we fail to load jQuery from CDN then I assume either CDN is down or we are offline, so i serve everything normally loaded from CDN.

benzonico added a commit that referenced this issue May 20, 2012
The following loading behaviour is implemented : we try to load everything from CDN, if we
fail to load jQuery from CDN, we assume either CDN is down or we are working offline.
In this case, we serve all of the librairies directly.
@tsimbalar
Copy link
Member Author

Nice !

A few answers to your comments :

I'll reopen the issue so that we don't forget doing it :)

@tsimbalar tsimbalar reopened this May 20, 2012
@benzonico
Copy link
Member

  • I saw that link while working on it : Problem is that the link for CDN on the blog post returns a 404 : this is the link that will serve the file from CDN not that is active right now. That's what I meant by Google is not reactive enough, if you read the comments, a lot of people are complaining about this.
  • I'll try to make the other two points work as you described them. (However the currently implemented solution can still be valid, but it can be more elegant)

@benzonico
Copy link
Member

And here it is.

  • The fallback are made. So for now, only the twitter bootstrap css are not hosted on a CDN as they are not available on any of them (and given the customization possible of those files I dunno if it will happen).
  • I have already prepared the jQueryUI for version 1.8.20, so while they are not available on google CDN, it fallback ou ours, and as soon as it will be available, the CDN will be used.

@tsimbalar I let you close the issue if you think it's good enough now, so the code is reviewed.

@tsimbalar
Copy link
Member Author

Nice !
Reviewed - closed

@tsimbalar
Copy link
Member Author

Ouch, I get a javascript Security error in Firefox when not connected to internet. The part that fails is when trying to access to the rules of a CSS file that comes from a domain other than the current host. The javascript error makes all the subsequent js calls fail, and therefore, some other js libs are not loaded ... Crap :-/

While investigating, I found yepnope which is a "resource loader". Looks like it knows how to retrieve both javascript and css with fallbacks. It may also be useful in the future when we try to support browsers that don't have native implementations of all the features we need (for instance websockets ... ). Also, it supports parallel loading of the files, and guarantees the order of execution.

Sorry, I have to reopen it :-/

@tsimbalar tsimbalar reopened this May 21, 2012
@benzonico
Copy link
Member

no time to look at it right now... I'll check later in the week.

@tsimbalar
Copy link
Member Author

no problem, no emergency :) . Maybe I'll have a look at it if time permits.

tsimbalar added a commit that referenced this issue Jul 5, 2012
* Google CDN still not offering the version we want... using microsoft CDN for now
* removed the css fallback that does not work too well ... to be improved with yepnope or something like that ...
tsimbalar added a commit that referenced this issue Jul 6, 2012
* oops, referenced wrong version of jQuery ... and it breaks the app :-/
tsimbalar added a commit that referenced this issue Jul 7, 2012
* use CDNs + minimized js when running in prod mode
* use unminimized js when running in dev mode

Note : ">play run" starts in "dev" mode while ">play start" starts in "prod" mode.
(see https://github.com/playframework/Play20/wiki/Production)
To test the prod mode on your machine, execute :
>play -DapplyEvolutions.default=true start
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants