PDA

View Full Version : [CLOSED] WebResource.axd resources are not gzipped. Is it possible to make Ext.NET's Resource Handler public?



anup
Nov 13, 2013, 5:34 PM
Hi,

In the Ext.NET book (p.321) I talk about using embedded resources for custom components, plus some scenarios where you might want to do this (as it is not mandatory) for example, to ship a component fully encapsulated, or to save the hassle of remembering to include the right resources in each page that might use the custom component (if you don't want to include it once in a master template or similar).

I've regrettably overlooked that these embedded resources, although they would use the ASP.NET web resource, will not get gzipped (seems a limitation to me; not sure why they don't support it - by comparison, ScriptResource.axd, does support gzip). Some module/handler-based solutions exist, but they seem to have side-effects from my quick look.

I guess the options, therefore, are

Stick with Embedded Resources and WebResource.axd (and manage any gzip/minification versions manually/yourself)
Try to create your own handler (can be tricky to get right to factor in gzipping, client caching support, minification, and so on)
Use Bundles (http://www.asp.net/mvc/tutorials/mvc-4/bundling-and-minification) from ASP.NET or similar custom bundling solutions that support gzip (and minification as a bonus)
Use Ext.Net.ResourceHandler (if it was public)? (As well as gzipping, this also supports minification as a bonus)


For my main project where I use Ext.NET I am seriously thinking of abandoning the Embedded Resource approach (in about 90% of the cases I think) in favour of migrating towards Bundles, as that will also automatically minify as well as compress and can be used with WebForms and MVC.

But would it be possible to make your resource handler public so it is usable by others? Looking at the code briefly it looks like there are some things specific to Ext.NET so it may not be easy to do that without some refactoring?

Or have I missed other options?

Thanks!

geoffrey.mcgill
Nov 13, 2013, 6:10 PM
Hi Anup,

This is related to functionality I've wanted to refactor and expand upon for some time. I will discuss with the team and see if we can improve upon the resource handling options for the 2.4 release (expected early December).

anup
Nov 13, 2013, 6:29 PM
Now you say that, I seem to remember a discussion where you mentioned that :)

Look forward to hearing about it.

anup
Nov 14, 2013, 8:32 AM
Hm... I think I found another place where I missed an opportunity to compress data, thinking IIS would do it for you, and it was a missed opportunity for the book, too.

It is in ashx, for example, when returning some raw JSON data, e.g. as part of a store paging ajax request. I often use (and gave examples of in the book) something like this:


context.Response.Write(JSON.Serialize(myObject));

I have assumed, without checking, that IIS will compress this because it has these kinds of settings in web.config:


<urlCompression doStaticCompression="true" doDynamicCompression="true" />

Since IIS 7.5 these are both defaulted to true, so not explicitly needed in web.config any more. But regardless, you would think all appropriate responses will get compressed. But as we have seen with WebResource.axd it doesn't. And that seems to be the case with ASHX (if using the above type of code). I am not sure why this is different as I would have thought IIS normally has a good layered architecture for this kind of stuff (it may be related to the way generic handlers take part in the processing pipeline and where that sits in IIS's pipeline, perhaps). Bit frustrating for this otherwise very nice and simple configuration. By comparison, in Apache, turning on compression is far more consistently applied!

But luckily your very useful method comes to the rescue here:


CompressionUtils.GZipAndSend(JSON.Serialize(myObje ct));

I'll look into this further, and maybe I'll post an update for my book on my blog if needed.

(Don't think this will really affect you on the Ext.NET side as this is more of a general issue with ASP.NET/IIS I guess, so it is a bit of an aside...!)

anup
Nov 14, 2013, 11:01 AM
(Don't think this will really affect you on the Ext.NET side as this is more of a general issue with ASP.NET/IIS I guess, so it is a bit of an aside...!)

I guess one area that could help is in the Examples Explorer. Where you have examples such as this:



public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "application/json";

StoreRequestParameters prms = new StoreRequestParameters(context);
Paging<Plant> plants = Plant.PlantsPaging(prms.Start, prms.Limit, prms.Sort[0].Property, prms.Sort[0].Direction.ToString(), string.Empty);

context.Response.Write(JSON.Serialize(plants));
}


You could replace it with this?



public void ProcessRequest(HttpContext context)
{
StoreRequestParameters prms = new StoreRequestParameters(context);
Paging<Plant> plants = Plant.PlantsPaging(prms.Start, prms.Limit, prms.Sort[0].Property, prms.Sort[0].Direction.ToString(), string.Empty);

CompressionUtils.GZipAndSend(JSON.Serialize(plants ));
}


This would apply to both Ext.NET 1.x and 2.x

Hope that helps.

michaeld
Nov 14, 2013, 11:09 AM
Anup, I ended up building my own handlers and compression tools (as well as minifiers) because of some of the concerns you raised. It was painful but I think I worked-through most of the scenarios. I'm even able to minify the embedded script generated by extnet or statically in my own code through use of Adapters. I technically have enough code to release a library. Maybe someday.

Vladimir
Nov 15, 2013, 5:31 AM
Hi

Now ResourceHandler supports web resources from non Ext.Net assembly, if a widget is inherited from Ext.Net control and placed in another assembly then its web resources (described in Resources property) will be extracted via Ext.Net ResourceHandler (with compression and caching)

anup
Nov 18, 2013, 3:14 PM
Vladimir, apologies for my delayed response. Just got latest and tried it out. Fantastic stuff! Many thanks. You can mark this as closed.

michaeld
Nov 18, 2013, 10:34 PM
Kudos on this...

Would this also work to register other additional external resource files from our own projects like you can do with ScriptManager?

anup
Nov 19, 2013, 1:22 PM
Kudos on this...

Would this also work to register other additional external resource files from our own projects like you can do with ScriptManager?

From the looks of it, it will work for your custom components where you override the resource property and point to other embedded resources.

But, if you have things like site-wide JS/CSS files you want to include, another options is using Bundles (http://www.asp.net/mvc/tutorials/mvc-4/bundling-and-minification)? It is quite powerful.

Hope that helps.

Daniil
Nov 26, 2013, 6:22 AM
Would this also work to register other additional external resource files from our own projects like you can do with ScriptManager?

There is a set of "Register..." methods in ResourceManager.

For example, this

protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
X.ResourceManager.RegisterClientScriptInclude("someKey", "someUrl");
}
}
produces the following in the output:

<script type="text/javascript" src="/someUrl"></script>

michaeld
Nov 26, 2013, 10:00 AM
<script type="text/javascript" src="/someUrl (http://forums.ext.net/view-source:http://localhost:51980/someUrl)"></script>


I think the forum screwed the output up but yeah, this above...

Nice. Thanks for taking the time to produce an example.

Daniil
Nov 26, 2013, 11:36 AM
I think the forum screwed the output up but yeah, this above...

Corrected, thanks.

So, Anup, @michaeld, can the thread be closed?

anup
Nov 26, 2013, 11:39 AM
Yes. please close. Many thanks for the responses.