Cache javascript source

A

Andrew Clark

Hello,

I have a webpage to search a database. When the results are returned
from the query, they are written to a temporary file so I can include
them as a javascript source file. On any subsequent query, the correct
recordset is written to the file, but the results on the page are not
updated due to (I suspect) caching in internet explorer. Here is an
example:

search.html
--

<IFRAME SRC="blank.html" NAME="dataiframe"></IFRAME>
[...]
<FORM ACTION="getdata.php" METHOD="post" TARGET="dataiframe">
<INPUT TYPE="submit"
</FORM>

getdata.php
--

// perform a query and write to a file here
$filename = "tmp/some distinct file name";
echo "<SCRIPT TYPE=\"text/javascript\" SRC=\"tmp/$filename.js\">";
echo "</SCRIPT>";

Each time the database is queried, the IFRAME is reloaded. The .js file
is created correctly (looking at the .js file, the values reflect the
new recordset), but the new data never shows up. The first data set is
the only one to ever show up. I think the contents of the javascript
file are cached and IE never bothers to reload it. How should I deal
with this problem?

Thanks,
Andrew
 
R

Rob Parsons

Hi Andrew,

I will take a wild guess at this one. I think you need to pass another
parameter with your form post (a page no. perhaps)..
What are you trying to do. Pagenate your results?
You can test if caching is a problem by deleteing your files between posts.
If you are still having problems then I would suggest you search the php
newsgroups. Usually someone has written some solid code that do what you
want to do before.
 
A

Andrew Clark

Hi Andrew,

I will take a wild guess at this one. I think you need to pass another
parameter with your form post (a page no. perhaps)..
What are you trying to do. Pagenate your results?
You can test if caching is a problem by deleteing your files between
posts. If you are still having problems then I would suggest you
search the php newsgroups. Usually someone has written some solid code
that do what you want to do before.

Thanks for your reply.

Here's what I'm trying to do: when the form is submitted, the database is
queried and a result set is returned based on criteria the user selects.
The result set is written to a .js file as javascript source so it may be
displayed using DHTML.

Each time the form is submitted, the .js file is created correctly, but for
the first recordset only do the correct results show up. The only reason I
can think of to explain this behavior is that IE is caching the .js file
and never reloading it.

This behavior does not occur in Firefox. That is why I think it is an IE
specific problem. Now I have a workaround in place to always generate a new
file and delete the old, but that seems messy to me. I would like to know
how to force IE to always read the .js file or not cache it.

Thanks,
Andrew
 
R

Rob Parsons

Hi Andrew,

Sorry for the delay. I am not sure if this will do the trick. I sorta don't
understand exactly how you are using js to write the results out
(document.write?)

But you may try the nocache header

<META HTTP-EQUIV="Pragma" CONTENT="no-cache">

The only other thing I can think of is to use a unique document.title for
each result set.
 
A

Andrew Clark

Hi Andrew,

Sorry for the delay. I am not sure if this will do the trick. I sorta
don't understand exactly how you are using js to write the results out
(document.write?)

But you may try the nocache header

<META HTTP-EQUIV="Pragma" CONTENT="no-cache">

The only other thing I can think of is to use a unique document.title
for each result set.

Thanks for your reply.

I am using PHP to write the result sets to a file, then including and
using the file with javascript. I tried

<META HTTP-EQUIV="expires" CONTENT="-1">

but that seems to have no effect on this problem. I saw the one you
mentioned as well and I will try it and get back.

Andrew
 
R

Rob Parsons

k saw your reply. Come back if it works. If it doesn't you may have to do
some research and maybe look for a different solution. There is bound to be
code out there that with a little effort can be modified to your needs.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top