Cache JavaScript Function in ASP

Results 1 to 2 of 2

Thread: Cache JavaScript Function in ASP

  1. #1
    Join Date
    Dec 1969

    Default Cache JavaScript Function in ASP

    I understand that one can use the following syntax so that a function is loaded once but may then be used by many pages:<BR>&#060;script LANGUAGE="JavaScript" src="jsFunction1.js"&#062;&#060;/script&#062;<BR><BR>In ASP one can include a JavaScript function thus:<BR>&#060;!-- #include virtual="jsFunction2.asp" --&#062;<BR><BR>I have several large JavaScript functions that I want to download from the server only once and use many times in web pages at the client.<BR>Does any one know how to combine these 2 methods?

  2. #2
    Join Date
    Dec 1969

    Default RE: Cache JavaScript Function in ASP

    I&#039;m not entirely sure what you mean. Do you understand what happens when you do either of those commands?<BR><BR>1: &#060;script LANGUAGE="JavaScript" src="jsFunction1.js"&#062;&#060;/script&#062;<BR>This says TO THE CLIENT "while loading this file, you need to request jsFunction1.js from the server". It loads the javascript file and the function and code are interpreted as if they are at that point in the page.<BR><BR>2: &#060;!-- #include virtual="jsFunction2.asp" --&#062;<BR>This says TO THE SERVER "before executing this file, you need to insert the contents of jsFunction1.js". It loads the TEXT of the js file and puts it at that point. Then, if the file is ASP, it&#039;s executed. If it&#039;s HTML, it&#039;s returned to the client.<BR><BR>The difference between the two is that the client knows that #1 contains two files, but it only receives one file for method 2. This means that if the client (or a proxy they use, or router, or...) has caching set up, it can cache BOTH pages - the page requested, and the include. Method two can only cache ONE page.<BR><BR>However, and this is the clincher, there&#039;s nothing to FORCE the client to use the file "included". If the client wants to request the file again, it&#039;s up to them.<BR><BR>So... Bearing ALL that in mind, can you rephrase your question?<BR><BR>Craig.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts