Dean-
I've managed to port your excellent javascript packer (version 2) to C# using the .Net Framework version 1.1. I have attached the source files along with an application that I used to test it (it's a lot like your packer page and html application). I also took the liberty of adding some rudimentary HTTP handler support to the file so it could be used to pack javascript from an ASP.NET server on request. I haven't quite tested it to death yet, but I believe it's ready for a beta release.
Now all we need is a brave .NET soul with time on their hands to roll this into an IHttpModule implementation, so that the js files stay unpacked on the server, but are packed on the fly (and cached, optionally) when requested.
Dimtiri – I didn’t bother with any logic to figure out which responses should be packed. Obviously, only Javascript files should be. But a file extension no longer means what it once meant. To be web-standard, an IF statement should surround my logic to sniff for the response’s content-type. But for that to work, your web-server must be setup properly.
So, your two, basic options are:
if (app.Request.Url.AbsolutePath.EndsWith("js"))
new ECMAScriptPacker().ProcessRequest((HttpApplication)sender.Context);
or
if (app.Response.ContentType == "text/javascript")
new ECMAScriptPacker().ProcessRequest((HttpApplication)sender.Context);
I believe I found the error that you ran into already. I’ve emailed an updated version to Dean, but I can send you an updated copy directly if you’d like. Feel free to email me directly with any porting problems at twindagger2k@msn.com
Harley-
I’ve never used the IHttpModule interface before, do you still have to set up IIS to send that particular extension to the ASP.NET executable this way? I was just using my web.config file to make .js extensions use the packer HTTP handler.
I’ve run into a max length on the textbox into which I’m pasting my code. It’s only taking 32766 characters. I haven’t compiled it myself or anything, I’ve only run the executable. Just thought I’d mention it.
I just started to use packer.net and got one interesting bug.
It isn’t reprodused on web page. But you can easily
reproduse it by capy and paste my simple test script into packer.net
“if (a) {} else /* not a */ if {}” – comment between else and if
“if (a) {} else // not a *
if {}” – that will do either
as a result of back transformation I got stange “elseif” word.
Comments (21)
Leave a comment
Comment: #1
Now all we need is a brave .NET soul with time on their hands to roll this into an IHttpModule implementation, so that the js files stay unpacked on the server, but are packed on the fly (and cached, optionally) when requested.
Comment: #2
Damned if I can get it to work. When opening it I get a “failed to initialize” error. I unzipped it, still no luck.
Comment: #3
Dante, you need to install the Microsoft .NET framework version 1.1. Have you done this? It worked fine for me….
Comment: #4
Comment: #5
Awww… I tried packing your cssQuery script using this (just wondering how big a script it can handle) but I got this:
Maybe it was too much for the packer to handle?
Comment: #6
Harley – Blimey that was quick! Only a few hours after a request for an IHttpModule, it gets posted.
Aankhen – the online version of packer can pack cssQuery OK. So there is probably a problem with Jesse’s conversion. I’ll contact him about this.
Comment: #7
Nice try harley. Now if only your module wouldn’t pack ALL files, just the ones that need to be packedAnd where’s my caching?
Comment: #8
Dimtiri – I didn’t bother with any logic to figure out which responses should be packed. Obviously, only Javascript files should be. But a file extension no longer means what it once meant. To be web-standard, an IF statement should surround my logic to sniff for the response’s content-type. But for that to work, your web-server must be setup properly.
So, your two, basic options are:
or
And, I’m just skipping the caching part
Comment: #9
Aankhen-
I believe I found the error that you ran into already. I’ve emailed an updated version to Dean, but I can send you an updated copy directly if you’d like. Feel free to email me directly with any porting problems at twindagger2k@msn.com
Harley-
I’ve never used the IHttpModule interface before, do you still have to set up IIS to send that particular extension to the ASP.NET executable this way? I was just using my web.config file to make .js extensions use the packer HTTP handler.
Comment: #10
Jesse – I used the second ZIP file that you sent me. Have you sent me another? I’m not getting the same error as Aankhen anyway.
Comment: #11
I can’t duplicate his problem either. Maybe he solved it.
Comment: #12
My apologies for the greatly delayed reply.
I redownloaded the packer, and this time it seems to work fine when compressing cssQuery. Thanks.
Comment: #13
This is fantastic work guys, it just keeps getting better and better.
Al.
Comment: #14
Is anone able to port the packer algorighm to perl?
Thanks Rob
Comment: #15
Rob, this hasn’t been done AFAIK. I would be grateful if someone did though. Are you volunteering?
You’ll need the source code of course. ParseMaster is a multi-pattern parser. There is probably something like it already in perl.
Comment: #16
Hi All! I pack js-files of FCKEditor2 with Packer .NET and got error in Firefox.
Source:
… String.prototype.replaceNewLineChars=function(replacement){return this.replace(/\n/g,replacement);}FCK_STATUS_NOTLOADED=… …
After Packing:
Firefox error: missing ‘;’ before statement
eChars=function(replacement){return this.replace(/\n/g,replacement)}FCK_STATUS_NOTLOADED=…
Why Packer eat ‘;’?
Thank you!
Comment: #17
alec – Packer not eat “;”.
See the usage page about terminating all statements with semi-colons. That includes function declarations.
Comment: #18
Hello
I’ve tested perl packer. It’s works very well. I need to check if special chars are supported.
I call it from PHP page that compile my js file in one before packaging. It’s very to make javascript licence system…
Maybe author could help me to make a native PHP version ?
Comment: #19
Hey guys,
I’ve run into a max length on the textbox into which I’m pasting my code. It’s only taking 32766 characters. I haven’t compiled it myself or anything, I’ve only run the executable. Just thought I’d mention it.
Comment: #20
Hi guys.
I just started to use packer.net and got one interesting bug. It isn’t reprodused on web page. But you can easily reproduse it by capy and paste my simple test script into packer.net
“if (a) {} else /* not a */ if {}” – comment between else and if
“if (a) {} else // not a *
if {}” – that will do either
as a result of back transformation I got stange “elseif” word.
‘if|a|elseif’.split(‘|’)
Comment: #21
Packer2.net —- Have a real simple question. Can somebody recopmpile this thing so that it can handle a file larger than 32,767 bytes???????????
Comments are closed.