Loading fresh JS code





11
Date Submitted Sun. Oct. 29th, 2006 12:52 PM
Revision 1 of 1
Scripter SCoon
Tags JavaScript | PHP | Web
Comments 0 comments
Enforce loadig fresh script code for the external javascript files. Compatible with HTTP 1.0.
<?php

function load_js($localPath) {
  if (file_exists($localPath)) {
    echo '<'.'script language="JavaScript" src="'.htmlspecialchars($localPath.'?'.filemtime($localPath)).'"><'.'/script>';
  } else {
    user_error("Unknown file:'$localPath'");
    exit;
  }
}

load_js('test.js');
load_js('there-is-no-such-file.js');

?>

...

 

Vladislav Zlobin

Comments

There are currently no comments for this snippet.

Voting