Re: CfC: Proposal to add web packaging / asset compression

On 2/14/2012 1:24 AM, Paul Bakaus wrote:
> window.loadPackage('package.webpf', function() {
>      var img = new Image();
>      img.src = "package.webpf/myImage.png";
> })
>
> Or alternatively, with a local storage system (I prefer option one):
>
> window.loadPackage('package.webpf', function(files) {
>      files[0].saveTo('myImage.png');
>      var img = new Image();
>      img.src = "local://<absolute path of url of site>/myImage.png";
> })


How about picking up FileSystem API semantics?

var img = new Image(); img.onload = myImageHandler;
var package = 'package.webpf';
var sprite = 'myImage.png';
window.requestFileSystem(package, 0, function(fs) {
     myPackagePolyfill(function(root) { img.src = 
root.getFile(sprite).toURL(); }, fs.root, package);
});

Packages would be calculated with the "temporary" file system quota.

I'm fine with it being a different method name, but re-using toURL makes 
a lot of sense.

I've heard more than once about how we shouldn't be requiring more 
formats. So I'd leave the mount format undefined, and just throw an 
error if it's not supported.
This still brings the package into the browser cache, it can be 
re-requested via XHR + ArrayBuffer (or blob), and manually parsed by JS 
polyfill.

 From a practical perspective:
Use uncompressed zip for packaging, it's trivial to support in JS these 
days.
Content is already compressed, typically, and deflate can be used in the 
request layer if the client-server relationship supports it.

Use the polyfill method to uncompress the files into the temporary file 
system if it's supported.
And if it's not supported, your polyfill can still use createObjectURL 
and file slice to handle business efficiently.

Just try to cleanup somewhere with a myPackagePolyfill.dispose(package);

-Charles

Received on Tuesday, 14 February 2012 13:14:56 UTC