SitePoint Sponsor |
|
User Tag List
Results 1 to 12 of 12
Thread: javascript stop cache
-
Sep 13, 2003, 04:47 #1
- Join Date
- Sep 2002
- Location
- Bournemouth, South UK
- Posts
- 1,551
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
javascript stop cache
How can I prevent an external javascript file from being cached?
any ideas?LiveScript: Putting the "Live" Back into JavaScript
if live output_as_javascript else output_as_html end if
-
Sep 13, 2003, 05:38 #2
- Join Date
- Sep 2002
- Location
- Canada
- Posts
- 2,087
- Mentioned
- 1 Post(s)
- Tagged
- 1 Thread(s)
Try
Code:<meta http-equiv="Pragma" content="no-cache" /> <meta http-equiv="Expires" content="-1" /> <meta http-equiv="Cache-Control" content="no-cache" />
"A nerd who gets contacts
and a trendy hair cut is still a nerd"
- Stephen Colbert on Apple Users
-
Sep 13, 2003, 13:54 #3
- Join Date
- Sep 2002
- Location
- Bournemouth, South UK
- Posts
- 1,551
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Thanks, but it didn't work with what I've been trying to do. I'm trying to save a variable to an external js using server side then reading it again client side. I've started a js file with this
Code:var myArray=new Array;
Code:<script src="array.js"></script>
Code:myArray[myArray.length]=(textarea.value)
Code:var myArray=new Array; myArray[0]="message 1" myArray[1]="another message" myArray[2]="third message"
Code:function reloadJS() { document.getElementsByTagName("script" )[0].src="array.js" ........... .......... setTimeout("reloadJS()",100) }
Is there any other way of reloading a javascript file?
ps I know 'document.getElementsByTagName("script" )[0].src="array.js"' only works in IE, but it seems it could be a fast option.Last edited by Markdidj; Sep 13, 2003 at 14:22.
LiveScript: Putting the "Live" Back into JavaScript
if live output_as_javascript else output_as_html end if
-
Sep 13, 2003, 16:42 #4
- Join Date
- Apr 2001
- Location
- Sarnia, Ontario, Canada
- Posts
- 434
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
You'll need to send a no-cache header with the js file.
I don't know what server your host is running, so I can't help you any more than that.Love it? Hate it? Helpful? Useless?
Use the rate button to let me know what you think of my post!
-
Sep 13, 2003, 16:46 #5
- Join Date
- Sep 2002
- Location
- Bournemouth, South UK
- Posts
- 1,551
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
can javascript files have headers? or is that to do with perl ? ( thats what I use). I dont want to make a html file containing js, it has to be pure js.
LiveScript: Putting the "Live" Back into JavaScript
if live output_as_javascript else output_as_html end if
-
Sep 13, 2003, 16:51 #6
- Join Date
- Sep 2002
- Location
- Bournemouth, South UK
- Posts
- 1,551
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
I heard quite a while ago that javascript can be run from server. Is that possible? That will stop it from being cached, but I can't find the info on it now.
LiveScript: Putting the "Live" Back into JavaScript
if live output_as_javascript else output_as_html end if
-
Sep 13, 2003, 17:30 #7
Originally Posted by Markdidj
.
-
Sep 13, 2003, 17:43 #8
- Join Date
- May 2002
- Location
- Relative
- Posts
- 452
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Do you use a server-side language? Try adding a random query-string to the <script> src tag, like this:
Code:<script language="javascript" type="text/javascript" src="somescript.js?rand=212293323"></script>
Of course, that's just my opinion. I could be wrong.
-
Sep 13, 2003, 19:28 #9
- Join Date
- Sep 2002
- Location
- Bournemouth, South UK
- Posts
- 1,551
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
I Tried
Code:document.getElementsByTagName('script')[0].src="messages.js?message="+Math.random*1000
Vinnie, I don't know about JSP, do I need extra plugins? Any good pages that demonstrates its capabilities? Thanks.....LiveScript: Putting the "Live" Back into JavaScript
if live output_as_javascript else output_as_html end if
-
Sep 13, 2003, 20:32 #10
- Join Date
- May 2002
- Location
- Relative
- Posts
- 452
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Why are you adverse to using server-side scripting to “rewrite” the page that then loads your script? You can’t add a random value in the way I described using client-side scripting; it must be server-side.
Of course, that's just my opinion. I could be wrong.
-
Sep 14, 2003, 02:17 #11
- Join Date
- Sep 2002
- Location
- Bournemouth, South UK
- Posts
- 1,551
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
It just seems long winded when I already have the page that I want loaded. It just means I have to get the perl script to do more work, when I only want it to save 1 variable. My thought was to do as much client-side as possible, so more people will be able to use the perl script at the same time.
I created a simple chatroom using this method (works on my computer but not online), and thought that it would also be useful for gamesLiveScript: Putting the "Live" Back into JavaScript
if live output_as_javascript else output_as_html end if
-
Sep 14, 2003, 09:06 #12
Originally Posted by Markdidj
PHP Code:<?php
//tell browser not to cache this page
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
//tell the server this is javascript content.
header("Content-type: text/javascript");
?>
//insert javascript code here
function foo(bar) {
return;
}HTML Code:<script type="text/javascript" src="javascript.php"></script>
Bookmarks