Flotype / now

NowJS makes it easy to build real-time web apps using JavaScript
http://www.nowjs.com
MIT License
1.91k stars 175 forks source link

Allow for reduced http requests #95

Closed AD7six closed 13 years ago

AD7six commented 13 years ago

Right now, there is one http request for now.js - which in turn makes one http request for each dependency, there is only one dependency, but that makes 2 http requests, and they are not served minified.

It would be more flexible if the now.js file served to clients was minified, and was self sufficient, this would allow users to include this file into their own build process such that http requests are reduced to a minimum.

So.. with this patch you can now do this:

 <script src="/socket.io/socket.io.js"></script>
 <script src="/nowjs/now.js"></script>

Or, more importantly, this:

 <script src="socket-plus-node-plus-myapp.min.js"></script>
tommedema commented 13 years ago

IMHO now should not host any javascript files, simply allow the dev to host it (and thus allow anykind of minified and merge version).

dvv commented 13 years ago

+1 for not hosting. It's really easy even for noobs to just put another <script src> line, or for more experienced to use dynamic loaders (requirejs, scriptjs, whatever consistent to their apps...). It would free nowjs from reimplementing dynamic loader and from responding to issues bound to browsers quirks.

AD7six commented 13 years ago

The ticket description is perhaps a bit misleading - I wrote it before the patch.

Do either of you have a comment on the patch (which simply allows you to do whatever you want) as opposed to the ticket description.

Perhaps it's not obvious but

<script src="socket-plus-node-plus-myapp.min.js"></script>

would be pointing at userland code, not a file served by now.js. If you want to do that now, you cannot include the served now.js file without modifying it (which is a chore to maintain) as it still requests socket.io.js by itself.

ericz commented 13 years ago

@AD7six, @dvv

I merged this but changed dependencies from an object to array of objects so we can still check to see if the dependency is already loaded without introducing the inefficiency of having to count the number of dependencies in the object manually or the use of ES5 Object.keys

Let me know if theres anything else I can do in this area

AD7six commented 13 years ago

Looks good to me - concern addressed :]