Forum Moderators: open

Message Too Old, No Replies

How can i get visited url's lastmodified date?

lastmodified from cache files

         

b0r0j0

6:31 am on Oct 11, 2009 (gmt 0)

10+ Year Member



I try to access to a remote resource by ajax,
i found that IE8 did not send request data to remote server.
So i try to fill "If-Modified-Since" in request header,
how i get the visited url's lastmodified date?

I'm really appreciate for you help!

whoisgregg

10:52 pm on Oct 11, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld, b0r0j0! :)

remote resource by ajax

The reason this isn't working is because you can't access files from other domains because of the browser's cross-domain security model.

If you set up a server side proxy, you can call that local script to fetch pages from other domains.

b0r0j0

1:20 am on Oct 12, 2009 (gmt 0)

10+ Year Member



Sorry,i should describe more clear.

The client page and remote resource is all in the same domain.
I use snifer catch browser's data.I found that:

The first time,IE really send request,
but secend time,IE use cache,did not send.

The resource is often change and big,
i need use cache normally,update it when it changed.

So i put the If-Modified-Since in the request header.
My code:

<script>
function getResource(url){
var req = new XMLHttpRequest();
req.open("GET",url, false);
req.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
req.setRequestHeader("If-Modified-Since",#);//Here # need to set a date string like 'Sun, 11 Oct 2009 05:32:53 GMT'
req.send("");
return req.responseText;
}

</script>

I'm don't know how to get the url's lastmodified date.It is in the system cache.

Thank you for help :)

whoisgregg

1:25 am on Oct 12, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ahh, I understand now. I think what you are looking for is:

req.getResponseHeader("Last-Modified");

An alternative to force a new download each time is by always appending a query string to the ajax request like so:

var url = '/path/to/script.php?time='+new Date().getTime();

b0r0j0

1:55 am on Oct 12, 2009 (gmt 0)

10+ Year Member



Thanks, so rapidly:)

Last-modified I can get it after request.
Can i get the url's lastmodified when the browser is just open.(I have not request yet,but i visited,i think it is in the system cache)

When we visit a page like "http://www.#*$!.com/a,html"
If i visited,IE will add 'If-Modified-Since' in the request automaticly.
I'm doult that can we get and add it manually in javascript?

whoisgregg

4:17 pm on Oct 12, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't believe that is available to Javascript. At least, I can't think of ever seeing anything that involved accessing the browser cache data in that way.

What you could do is store the value of last-modified the first time the page is requested, then store that value in a cookie.

b0r0j0

11:56 pm on Oct 12, 2009 (gmt 0)

10+ Year Member



Thanks a lot:) It seems too difficult ,i try another way.
Good Luck!