[thelist] JavaScript - Pull from another site and display....

Maximillian Schwanekamp lists at neptunewebworks.com
Fri Oct 8 12:06:30 CDT 2004


Matt Warden wrote:

>>piece of javascript and paste it onto their site.  The javascript will
>>grab some dynamic information from a site and will allow me to
>>customize the output.
>>
>You can do this by creating a javascript file, full of
>document.write()'s
><snip /> ...you
>could use dynamic script (like PHP) to create the js file. Then you
>would want to do something like this:
>
><script src="http://foo.com/ext/asdflkj.php" type="text/javascript" />
>
><snip />
>Anyone have any ideas of how to avoid caching issues without using
>dynamic script? Obviously you could try using PHP to set no-cache and
>expires headers, but YMMV with those.
>
I have used no-cache headers with php javascript in the past without 
issue.  To be on the safe side, use all the cache-related headers, and 
make sure to set the content-type, and all should be well:

header('Content-type: text/javascript');
header('Expires: Mon, 20 Dec 1998 01:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-cache, must-revalidate');
header('Pragma: no-cache' );

If you want to obfuscate the fact that you're using PHP, you can add an 
Apache directive in .htaccess to map the .js extension to php:
AddType application/x-httpd-php .js
(This is of course assuming you're using Apache).

-- 
Maximillian Von Schwanekamp
Dynamic Websites and E-Commerce
NeptuneWebworks.com <http://www.neptunewebworks.com/>
voice: 541-302-1438
fax: 208-730-6504



More information about the thelist mailing list