I am not sure if this is the right forum. I want to generate dynamic .js script from C#. Here is what I am doing: In my HTML file, near the end, I have the following: <script defer type="text/javascript" src="http://mydomain.com/test.aspx"></script> ========
The test.aspx generates the script like this: <script runat="server"> string ip_addr; void Page_Load (object sender, EventArgs e) { ip_addr = Request.ServerVariables["REMOTE_ADDR"]; } </script> document.write('Test4: '); ========== This works fine except that
if I change the test.aspx to change Test4 to Test5 and so on, I can see that the browser keeps showing the old output even on refresh. That means that in my .js generation, I am missing some sort of http header that tells server that the file has changed.
How can I gode the test.aspx file properly so that a change can be communicated to the browser just like a real .js file sourced in from the disk? Thanks.
You are doing every thing correctly. But your browser is probably caching output from test.aspx, try to disable output caching of test.aspx (excusively on client side) using location attribute of OutputCache directive.
Jigar Desai -----------------------
Do not forget to "Mark as Answer" on the post that helped you.
I agree with Jigar---IE is caching like there's no tomorrow. I've tried your code by creating test4.aspx, test5.aspx, test6.aspx and noticed the same problem, i.e. IE ignores it when you change your "launcher" page. Interestingly enough, I also tried this in
the Mozilla 1.6 and Firefox 0.8 and everything worked fine! Even Opera 7.23 which has always been notorious for insane caching handled this correctly. Anyway, I think this calls for some tinkering with caching headers. :(
I did some research on usenet and found this solution that seems to work: In my Page_Load I put this: Response.ContentType = "text/plain"; Response.Expires = -1; Response.CacheControl = "no-cache"; I am not sure which one makes it work but it does. Thanks.
winenthu
Member
35 Points
7 Posts
Generating .JS file from aspx
Mar 01, 2004 03:45 PM|LINK
Jigar
Contributor
4629 Points
935 Posts
Re: Generating .JS file from aspx
Mar 02, 2004 01:09 AM|LINK
-----------------------
Do not forget to "Mark as Answer" on the post that helped you.
MilanNegovan
Participant
1421 Points
296 Posts
MVP
Re: Generating .JS file from aspx
Mar 02, 2004 04:47 AM|LINK
http://www.AspNetResources.com
ASP.NET With Emphasis On Web Standards
winenthu
Member
35 Points
7 Posts
Re: Generating .JS file from aspx
Mar 03, 2004 06:55 AM|LINK