<script src="/js/supply.min.js?v=2"></script> <script type="text/javascript"> supply.setDealer('/cgi-bin/supply.pl').files({ debug: false, javascript: [ '/js/jquery-1.4.2.min.js', '/js/jquery-ui-1.8.4.custom.min.js', '/js/init.min.js', '/js/box.min.js', '/js/app.min.js' ] }); </script>
That's how your script loading could look like in the future.
What happens here is simple. "supply.min.js" is loaded via the conventional method. After that, "supply" is available in the global namespace. The setDealer() method can optionally be called to tell the script where it can find it's backend counter part. Finally we call files() and pass in an object literal with the key "javascript" which value contains an array of javascript filenames.
Now supply creates a request to "supply.pl". Our Dealerscript does it's work, fetching and concatenating all our desired files on the server and sends us one big chunk of data back. Voila.
Supply.js codereview:
I have to apologize for the quality, it's my first record. Hope you like it anyway.
Source:
https://github.com/jAndreas/Supply
Download:
https://github.com/jAndreas/Supply/zipball/master
{}.toString is slower? why? Beside that, pretty interesting stuff. But I would really like to see some measuring, Supply vs. (AnyOtherScriptLoader) for instance.
ReplyDeletehttp://jsperf.com/object-prototype-tostring-call-vs-tostring
ReplyDeleteThat should prove it. I will try to come up with some benchmarks soon. Can we extend a day to 36 hours or something? :p