You are correct that this is the wrong newsgroup for discussing PHP.
However, how to integrate "js" with e.g. PHP should be on-topic.
An alternative to having PHP process all ("js") files as well (which also
includes having to prepend a suitable header() call as the default Content-
Type is `text/html', on top of the inefficience) is
in foo.php:
<script type="text/javascript">
var client_side_data = <?php echo json_encode($server_side_data); ?>;
</script>
<script type="text/javascript" src="bar.js"></script>
<script type="text/javascript" src="baz.js"></script>
bar.js:
… client_side_data …
This can be automated with server-side scripting; for example, in an MVC-
based application you can have controller methods along the lines of
<?php
class FooController extends Controller
{
…
protected function _prepareHead()
{
…
$this->addClientScriptVar('data', $this->data);
$this->addClientScript('bar.js');
$this->addClientScript('baz.js');
…
}
protected function _getData()
{
…
$this->data = ModelMapper::getData();
…
}
…
}
?>
that would cause client-side code to the effect of the above code to be
generated. (We are doing something like this in a Zend Framework/Ext JS-
powered *internal* Web application. [No, Ext JS was not my decision to
make, and I could not do anything about it when I joined the project.
Suffice it to say that I was glad that they had not chosen jQuery or worse
instead.])
The advantage of this is that you can define runtime modes from the server-
side: a debug mode where the included client-side scripts still contain all
formatting and inline documentation; and a production mode where they are
combined into one large script, devoid of all comments, and even
automatically minimized.
The FAQ
<
http://webcache.googleusercontent.com/search?q=cache:http://jibbering....>,
which original is currently offline again (as is the Internet Wayback
Machine), should be complemented with this or a similar suggestion.
Another possibility is XMLHttpRequest; that approach can also be combined
with the aforementioned one (and in our application we are doing so).
PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <
http://www.vortex-webdesign.com/help/hidesource.htm> (404-comp.)