none
How to clear the Cached JScript file in a Page in PWA 2010?

    질문

  • Hi all,

    I am Working with PWA 2010.

    I have to develop a visual web part, which in turn has some Jscript files attached to it.

    When there is a minor changes to Jscript files, I dont want to uninstall & Install the web part to the gallery.

    Is there any way to create a empty web part whcih clears the cache when it is added to the page?

    Some where I had seen the following code which makes sure that latest Jsciprt file is used. But could not get what it does?

    protected override void OnInit(EventArgs e)
            {
                base.OnInit(e);
    
                if (IsAjax && HttpContext.Current.Items[PROCESSED_KEY] == null)
                {
                    HttpContext.Current.Items[PROCESSED_KEY] = true;
    
                    string json = GetAjaxData(Page.Request.QueryString["q"], Convert.ToInt32(Page.Request.QueryString["limit"]));
    
                    Page.Response.Clear();
                    Page.Response.AddHeader("Cache-Control", "no-store, no-cache, must-revalidate");
                    Page.Response.AddHeader("Expires", "Thu, 01 Jan 1970 00:00:00 GMT");
                    Page.Response.AddHeader("Pragma", "no-cache");
    
                    Page.Response.Write(json);
                    Page.Response.End();
                    Page.Response.Close();
                }
            }

    Can any one tell me, if there is a better way to do it?

    Thanks !


    Muniappan

    2012년 6월 14일 목요일 오후 12:34

답변

  • Thanks a lot Dan.

    Some how that did not solve the issue actually.

    I don't need to clear the IE cache , Instead I just need to do IISRESET. Simple one but Good one ! :)

    Thanks !


    Muniappan

    • 답변으로 표시됨 Muniappan S 2012년 6월 15일 금요일 오후 2:07
    2012년 6월 15일 금요일 오후 2:07

모든 응답

  • Hi,

    If you are referencing your js files in your code just add a DateTime as a QueryString parameter like this:

    <script src="path/to/file.js?d=<%= DateTime.Now %>" type="text/javascript" ></script>

    Cheers,

    Dan.


    You can find my blog here: http://developertrack.blogspot.com



    • 편집됨 Dan Grigore 2012년 6월 15일 금요일 오전 6:26
    2012년 6월 15일 금요일 오전 6:24
  • Thanks for the reply. But my problem is that I am changing some of the out-of-box JScript files. So I have no idea where it had been hooked for that page. More over I have no interest in changing the main/master page. Is there a possibility to do the same with the help of a custom web part...?

    If I am able to create web part which does not allows the caching of Jscript files on which it is associated, there on I can use the same web part in different pages.

    Thanks !


    Muniappan

    2012년 6월 15일 금요일 오전 7:10
  • Hi,

    I wouldn't recommend editing the out of the box SharePoint JavaScript files.

    This is a browser cache issue - and it can be solved by clearing the browser cache.

    Anyhow, the web part code you have seems alright - although I'm not sure how often you will change these files so that this web part is justified.

    Cheers,

    Dan.



    You can find my blog here: http://developertrack.blogspot.com

    2012년 6월 15일 금요일 오전 8:02
  • Thanks for the reply. Yes I agree. But there are situations that compels to do it.

    Yes, of course the clear cache will solve the issue, But we can not expect/force user to clear the cache whenever required, that too when we have large number of users.[Informing the user will be a tedious things...mailers will not reach the 100 %]

    But the Code that I had shown above was not working fine for me.[When the webapart  is added, Page goes blank.] I am not able to get the data to write to "Page.Response.Write". :(

    Atleast If I know how check the version[JScript file date of change] that exists in the "Temporary Internet Files" folder, I can prompt the user to clear t cache and try. But When I try to check the "Temporary Internet Files" folder through code, these jscript files are not shown. Any Idea ho these files are stored in the folder? Are they really stored in cache? if so, at least how to get the last modified date for particular JScript file.

    Thanks !


    Muniappan



    • 편집됨 Muniappan S 2012년 6월 15일 금요일 오전 9:26
    2012년 6월 15일 금요일 오전 9:24
  • Hi,

    Your page goes blank because you are closing the request:

    Page.Response.End();
    Page.Response.Close();
    

    You can try to comment these lines and try again.

    Cheers,

    Dan.


    You can find my blog here: http://developertrack.blogspot.com

    2012년 6월 15일 금요일 오전 9:39
  • Thanks a lot Dan.

    Some how that did not solve the issue actually.

    I don't need to clear the IE cache , Instead I just need to do IISRESET. Simple one but Good one ! :)

    Thanks !


    Muniappan

    • 답변으로 표시됨 Muniappan S 2012년 6월 15일 금요일 오후 2:07
    2012년 6월 15일 금요일 오후 2:07