Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
142
rated 0 times [  145] [ 3]  / answers: 1 / hits: 17404  / 14 Years ago, fri, october 15, 2010, 12:00:00

I have a JavaScript file where I would like to include some php code.
The problem is that I have a few defines on PHP that I would like to use on JS as well.



Is there any way of including a .js file in HTML allowing the server to first interpret it (before downloading to the client) using php?



Thanks :)


More From » php

 Answers
19
<script src=/path/to/my/file.php></script>


In file.php you'll also want to output the correct header, before outputting anything you should have the following:



header(Content-Type: application/javascript);


EDIT: As @Tony_A pointed out, it should be application/javascript. I don't think it mattered as much when I wrote this post in 2010 :)


[#95309] Wednesday, October 13, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
shaynelandenb

Total Points: 293
Total Questions: 97
Total Answers: 94

Location: Monaco
Member since Fri, Sep 24, 2021
3 Years ago
;