Forum Moderators: phranque

Message Too Old, No Replies

External JS file not being cached?

         

blang

5:37 pm on Jan 29, 2010 (gmt 0)

10+ Year Member



Hey guys & gals; in reviewing the server stats (AWstats) for one of the domains I manage, I'm seeing a single externally linked JavaScript file (gzipped) as one of the top three requests. This script is included in an HTML template that is used by the server-side script to output dynamic content.

My question is, could it be this file is simply not being cached, and if so, how can I force caching of this file? How can I test this principal?

The alternative is of course, that it's being hotlinked, but I can't imagine someone would want to do this as it is an obfuscated set of JS functions that are custom designed for this site.

blang

7:36 pm on Jan 29, 2010 (gmt 0)

10+ Year Member



Following up to this issue, I've used the FireFox Firebug utility to confirm the JS file is in fact being cached, because it is only requested once on the first fresh page load (or when I force the cache to be refreshed). So for 100 requests to a server-side script to output dynamic content, this JS file is only requested and sent once.

What else would be causing such a high request rate for this one file? I'm reviewing the list of referrers, and I found a couple that are attempting to hotlink images, but I can't see someone trying to use this JS code on their own site...

BTW, the htaccess only has anti-hotlinking for images, I need to get a rule into place for JS / CSS files anyway I suppose.

Demaestro

7:50 pm on Jan 29, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Have you confirmed that all the requests are internal (from your site)?

I have had JS redirect methods "hotlinked" before.

blang

8:13 pm on Jan 29, 2010 (gmt 0)

10+ Year Member



Good idea, but I don't know how to find that; AWstats only shows either the most requested URL or links from external referrers, not both. It would be nice if the stats for each URL was linked to a count of external / internal, but it doesn't exist. There's probably a Perl one-liner to scan the log file and spit out whether the request was external, but I don't know Perl well enough to head down that road.

Demaestro

8:24 pm on Jan 29, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



blang,

Check your raw server logs, they should be located 1 directory down from your public_html folder... probibly named something like "logs"... inside there should be 2 files, 1 named something like access and one named something like error.

Open the access file, (it is just a plain text file so notepad or something similar can open it) then do a "find" for the name of the JS file, then look at the line and it will show what page requested it, what ip and so on. Look up a bunch of them and see if there is a trend that explains the high amount of times it has been called.

If you have questions about finding the file or what you are seeing with the file open, post back here.

blang

8:41 pm on Jan 29, 2010 (gmt 0)

10+ Year Member



Thanks for your input; I was actually ahead of you. I had SSH'ed into the server and was using grep to find that string on either the error or access log. There are a couple of mentions of the file in the error log (probably some sort of request fluke), but the access log doesn't even mention it. Not a single occurrance. Could it be because it's a gzipped file?

The access log dates back to October '09, BTW.

Demaestro

9:05 pm on Jan 29, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I would wager that it is because it is gzipped, but my network admin knowledge is limited so I am guessing.

I may be wrong but I thought AWstats used the access_log file to generate that server data.

Does anyone else have any insight into this?

phranque

11:48 pm on Jan 29, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



is it possible you script is doing a HTTP Get of that javascript file and processing or inserting the javascript?
have you looked at the page source?
i.e. is it actually a script element with a src= attribute requesting an external js file from your server?

blang

1:02 am on Jan 30, 2010 (gmt 0)

10+ Year Member



i.e. is it actually a script element with a src= attribute requesting an external js file from your server?

Oh yes. It's all static markup with the JS script element near the bottom of the body so it loads after the page has loaded. The server-side script (PHP) includes two static markup files: the head and the 'tail' (anything after the main content), and anything in the middle is dynamically produced based on the request. The JS script element lives in the 'tail'. The markup is HTML4 and it validates.

To clarify, it's not an "external" script as in "external to this domain", but it is external to the document. In other words, it's in a local directory with the other JS libraries, it's not being requested from Google or some other server.