Friday, October 3, 2014

Things I wish Servers did

Ruby has Gems. The .Net platform has Nuget. JavaScript has NPM. Package managers are being used more and more.  The reason? They are awesome. They are awesome because you just say what you need in a single simple statement and then the package manager does all the work of downloading, installing, and dependency management. The package manager will know what to download.

What I wish clients (browsers) had was a package manager. I have thought about how this could work. You have an authority. People with JavaScript they want to be loaded via a package manager submit it to an authority with a namespace (would include a version). You would also submit a list of dependencies and potentially a place the code resides. In your code you would add an attribute to your script tags like "location = JQuery.Plugins.Widget.v7_0_1". Then the browser would check the package manager for this code. Any code required by this plugin would be automatically downloaded by the browser. You could optimize this to be minified code all delivered in one gzipped chunk. Then you would ignore the actual script tag. You could do caching based on the namespace. This somewhat duplicates what CDNs do, but has a cleaner mechanism.

I think this would encourage re-use of components. Also you could do some interesting metrics by having the package manager authority record who has what.

The other thing I wish browsers did was allow you to list in your response header what domains you allow XHR requests to go to. Does this create perfect security? Not really, because it doesn't stop scripts getting injected into your page. But it does make it harder for any injected script to do things like send your data elsewhere or to load more complex scripts.

The other thing I wish the browser did was send you a capability list. So I think the right thing to do with JavaScript is write in Harmony (ES6) and then use a transpiler. You should have a system where good browsers load your Harmony code, but shitty browsers (IE8-) load your transpiled code. Don't make good browsers run bad code. Have good browsers quickly load good code to run quickly. Old browsers can load and run slowly. Of course you can do this by pre-loading a JavaScript "shim". The shim could potentially do lots of things like cache management.

No comments:

Post a Comment