Evaluating php generated javascript "inline"?

Posted by talkingnews on Stack Overflow See other posts from Stack Overflow or by talkingnews
Published on 2010-06-16T00:51:14Z Indexed on 2010/06/16 1:02 UTC
Read the original article Hit count: 376

Filed under:
|
|
|
|

If you look at the source of this page http://kingston.talking-newspapers.co.uk/ you will see a large amount of inline javascript near the top.

I don't really want all this extra stuff floating around in my page source, I'd much rather get it off into a script tag, and then I can minify it and all sorts.

If I call it as a php file, this SHOULD work in theory, I just end the js file extension with php instead, and in the header I put the following:

header("Content-type:application/x-javascript");

but... a lot of the php variables used to generate the playlist within the javascript are setup at the beginning of the main index.php file, and in calling this php-generated js playlist file like this, it seems to evaluate it entirely separately, so it's full of errors.

The only way round it I can think of is to have the page write a file, then immediately read it in. The other thing is, the playlist is likely to change often and dynamically, so I think I need to get minify to NOT cache it?

© Stack Overflow or respective owner

Related posts about php

Related posts about JavaScript