malko / l.js

another js loader

Home Page:http://malko.github.com/l.js/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Retry support

ivanrey opened this issue · comments

Hi Malko,

I added a retry support to my version of l.js. It basically uses the #id part of the url to give a second url and in case the script fails to load it will retry with the #id url.

For us is helpful since we use a lot of CDNs and some are blocked in internal clients, so this way we can fallback to the local version of the file.

I don't know if you're interested in adding this support. It certainly needs review and I would like to make it optional also (maybe with the same mechanism as checkLoaded?)

i'm actually reviewing your code, certainly will commit my revision this night. I'm not a big fan of this feature for the following reasons:

  • onerror is not support on all browsers
  • the hash part is already used to set the generated tag id and i needed this feature at the time i wrote l.js
  • even if we implement this feature i'm not certain this has to be detected in the checkloaded part of l.js as this is only to detect already included script tags.
    On the other side, l.js was at first designed with mobile devices in mind and most of those browsers support the error event. As a user of l.js you express a need that seems legit and fair to me, so it's nice of you and l.js is there to be helpful so let's make it better sweet your needs certainly others may have interest in this.
    So here's what i propose:
  • we don't check for fallback in the checkloaded part but systematicly remove the hash part from those urls.
  • we keep the hash for ids most of the time
  • we use #= to define a fallback url e.g. http://cdn.com/mylib.js#=/mylib.js
  • no need for this to be an option in this way it can be use sytematically
  • eventually we can add support for double # e.g. http://cdn.com/mylib.js#=/mylib.js#myId (this will add an extra overhead to the lib i need to think about)

What do you think ?

Ho and i forgot, but thanks for your contribs anyway ;)

I think it's a very good idea.
I'm ok with the #= syntax that way we can use both id and fallbackURL. That way we don't have to check for the .js which I didn't find very elegant.

I think the overhead shouldn't be too much if the same regex can be used for both things.

I originally thought the id part was used for the check instead of the URL, once I saw the check was made with the URL I didn't find the use for the Ids, but I think is best to keep backwards compatibility so the library helps more people.

I have updated my code to reflect these changes. Please let me know what you think. (It might need some testing, I wrote it in github directly, I will test it later)

Should I turn this into a pull request so you can comment directly on the code?

I'd already pulled your code and made some rewrite to go in the direction we stated in my previous comment. You can update and test if this work as you intended so.
Don't hesitate to report specific browser bug report i have only chrome at the moment to test on.
Thank you again.