Show HN: MicroEvent.js - js micro event emitter in less than 20lines
notes.jetienne.com
notes.jetienne.com
A couple small suggestions and thoughts:
Add a couple lines so that all methods return this; to allow for chaining, especially helpful when using it as a mixin.
Rename bind/unbind method names since they have completely different meanings/uses in ES5:
https://developer.mozilla.org/en/JavaScript/Reference/Global...
P.S. If you're down with those changes I'll gladly fork, update and send a pull req, although not sure what you'd want to rename the api too.
your point on api name is good. which name would you suggest ? something standard and readable and im sold :)
subscribe/unsubscribe/publish
and also added return this.
If you have a custom backend, you could always give it a list of frontend scripts to send and send them all to the browser as one big virtual "scripts.js" file. Then you get the best of both worlds - all the scripts in one HTTP request, but in a separated, maintainable file structure on the server.
(The modified date to compare to/set scripts.js for caching purposes would be the highest out of all the script files, obviously)
You should probably still try to use the major CDNs for very popular libraries like Prototype, jQuery, etc. These are more likely to pull from cache and not incur any additional transfer time.
The best and brightest in the JS performance area now mostly advocate using some form of loader to load the JavaScripts, bearing in mind that the overall page speed and perceived performance can be affected by more factors than simply the number of script files that need to be requested. Hence the recent proliferation of things like yepnope.js, require.js, lab.js etc.
The fastest and best approach for your particular site will be specific to your site and there is no generic solution guaranteed to be optimal.
I like micro frameworks (aka tiny libraries) because it is standalone and so small you can easily maintain it yourself if needed. So it is less an actual dependancy.