tags:

views:

52

answers:

1

I have a controller action that returns a large amount of dynamic JavaScript (gets served once to the client) and I already have GZip compression enabled. One thing I'd like to do is read the executed result stream and apply JS minification on it.

Is it possible to do this using an Action Filter Attribute. I think my question boils down to - Assuming my minifier takes a string of JavaScript is there a way to pull the executed result as a string out of View(view).ExecuteResult(ControllerContext) ?

+1  A: 
amarsuperstar
Yes it will perform the minification but that wasn't my question. Assuming I have a result like `View()` I want to be able to take that stream and convert it to string, minify and write it back to another result (or directly to the response if necessary)
kouPhax
Aah, sorry I misread the question. You need a response filter which you can hook up within an ActionFilter Attribute, similar to this: http://stackoverflow.com/questions/1640909/asp-net-mvc-response-filter-outputcache-attribute
amarsuperstar
I think that is along the same lines however I still don't think it's the same issue. I guess it could be implemented as a filter (stream) though I am not 100% sure how to go about that.
kouPhax
See my update :-)
amarsuperstar
Excellent this is what I was wanting. On final question though - Why the use of Close vs Flush. I recently found a similar solution but it used Flush and I was wondering which is better and why?
kouPhax
I'm no expert, but I think Close is safer than Flush, since ASP.NET could flush the response several times if it is large and they want to start sending data to the client. By the time Close is called, atleast by this time it is definite that the output stream has finished. Hope that is vaguely clear
amarsuperstar
Makes sense. Thanks.
kouPhax