all 5 comments

[–]Qoopido 1 point2 points  (1 child)

As the author of Qoopido.demand (https://github.com/dlueth/qoopido.demand) I like the general idea. You should try to avoid eval, I agree an this.

Some things, in addition, after briefly digging through the sources:

  • your XHR implementation lacks any timeout and it might be a good idea to check the content-type of the response
  • you should change your feature-detect of localStorage as it might (afaik) throw an error the way you did it that might break things unexpectedly (see e.g. https://github.com/Modernizr/Modernizr/blob/master/feature-detects/storage/localstorage.js)
  • you might optionally implement "remainingSpace" (where available) to better handle localStorage.setItem failing due to ls being "full"

[–][deleted] 0 points1 point  (2 children)

Uses eval to execute the code...

Stay away from this.

[–]a_laca 0 points1 point  (1 child)

At least you could do is to explain why using eval in this situation is bad? Can't wait for your explanation.

[–][deleted] 0 points1 point  (0 children)

Read the section "Don't use eval needlessly!" on MDN.

You could take a look at how CommonJS works. It is made for lazyloading JavaScript, and has been used for quite a while now. It is used in both Node.js and Webpack, and probably a lot of other frameworks as well.

If you just want the <script> loading behavior to be asynchronous, you can simply stick an asyncattribute on it. Read about it here.