My application has been set to cache its resources, but the file ig_WebGrid.xslt is never being cached, and is producing a big overhead. Because is being requested and downloaded several times.
Any idea why this happen?
Dyzann,
I always enjoy a new challenge.. I decided to try and reproduce this myself and I ran into something interesting. As you already noted - the request header has "pragma no-cache". I had assumed this was a response header when I first read your post. So, I dug some more, and found that we're dynamically loading the XSLT file - it's not being imported through a tag. There's nothing wrong with this, but Microsoft mentions in the documentation that this pattern is used for "dynamic content". Dynamic is another word for "we better not cache this".
My guess right now is that the implementation of the Microsoft XMLDom.load method sets this request header to prevent headaches for those who are serving up dynamic XSLT files. Again, this is just an assumption becasuse I was able to find very little documentation on how this works.
As a workaround, I decided to try using the loadXML method instead, and manually requesting the XSLT file with an XMLHTTPRequest. The result is extremely promising, since Fiddler now doesn't even show a request for the file happening! The following code replaces a method in ig_webgrid_dom.js
function igtbl_XSLTProcessor(xsltURL){ if(!xsltURL) return null; if(ig_csom.IsIE) { var xslt=ig_createActiveXFromProgIDs(["MSXML2.FreeThreadedDOMDocument","Microsoft.FreeThreadedXMLDOM"]); xslt.async=false; var http = new ActiveXObject("Msxml2.XMLHTTP.3.0"); http.open("GET", xsltURL, false); http.send(); xslt.loadXML(http.responseText); var xslTemplate=new ActiveXObject("MSXML2.XSLTemplate"); xslTemplate.stylesheet=xslt; this.Processor=xslTemplate.createProcessor(); } else { var xmlResp=new DOMParser(); var xmlHttp=new XMLHttpRequest(); xmlHttp.open("GET",xsltURL,false); xmlHttp.send(null); this.Processor=new XSLTProcessor(); this.Processor.importStylesheet(xmlResp.parseFromString(xmlHttp.responseText,"text/xml")); }}
I am using IE. And no i dont have the IE set to delete all the content.
What confuses me big deal, is that i have set the cache and all. And the only file that is not being cached is the ig_WebGrid.xslt, the rest of the files are being cached, images and .js and other.
I really dont know what is going on with this. Our pages use Infragistics heavily, and therefore this specific file produces an important overhead, if it would be requested just once each time the page is requested... But is being requested 8 times, in the page I am working on right now, because there are 8 Infragistics controls on the page. And this is each time the page is being requested.
I will keep researching on this, and i hope i can find where i am mistaken.
Thanks for your answers!
Regards.-
The grid adds a script tag to the HTML output which has the URL to the xslt file. Other than that, the grid has no control over how or where that file comes from. What browser are you using to view the files? Is it possible that you have changed your browser settings to remove all temporary internet files (the browser cache)? Also, if you click on the refresh button for a page, all cached content will be downloaded again. Is it possible that your method for testing is involving forcing the browser to re-download the content?
Thanks again for your answer.
I have been researching about what you indicated me. I have set the Cache-Control as you indicated me and in other diferent ways.
No matter what i do always happen the same, I see in the response of the server that the Cache-Control i set is being set in it as i indicated. But the request always has Pragma: No-Cache. And then the files are always received several times.
Is possible by any matters that i am configuring something wrong on the grids that forces the "Pragma: No - Cache" and that is why i get several times the same file?
Or maybe i am just missunderstanding the way this function.
I see that this same file is sent several times, once for each Infragistic control that i have on the page. And this just doesnt seem right, since is always the same file. Maybe this is the way is supposted to work?
Sorry for this so many questions, and thanks again for your answers.
The pragma: no-cache header is added by your webserver, not the WebGrid. You should set an expiration for the content using the cache-control header. For example:
Cache-Control: max-age=3600, must-revalidate
I don't spend a lot of time in IIS, so I'm not sure if there's an easier way to acheive this. Perhaps some of your peers have more experience setting cache control in IIS.