August 2nd, 2012, 07:49 AM
-
Parse .js files as php and serve with correct content type
I am trying to parse certain .js files as php - I can isolate just the files I want with the directory and FilesMatch directives and I can get PHP to process them. One thing I cannot get the setup to do is to serve the processed files as anything other then "text/html"; preferably I'd like to serve them up as JavaScript.
I have this config in my vhosts conf file:
Code:
<VirtualHost 127.0.0.1:80>
ServerName dev.local.abcde.com
DocumentRoot C:\xampp\htdocs\dev.abcde.com\trunk\www
ErrorLog "C:\xampp\htdocs\dev.abcde.com\errors.log"
<Directory "C:\xampp\htdocs\dev.abcde.com\trunk\www">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<Directory "C:\xampp\htdocs\dev.abcde.com\trunk\www\app">
<FilesMatch "\.(js)$">
php_value auto_prepend_file "C:\xampp\htdocs\dev.abcde.com\trunk\www\app\js-start.php"
AddType 'text/javascript; charset=UFT-8' .js
AddHandler application/x-httpd-php .js
</FilesMatch>
</Directory>
</VirtualHost>
even the js-start.php file has a php header function call to set the content type
This is happening both locally on my widows computer (conf as shown above) and on my staging server (RHEL)
I've attempted with .htaccess as well in just the appropriate folder but that doesn't work either.
August 2nd, 2012, 08:46 AM
-
even the js-start.php file has a php header function call to set the content type
This by itself should be sufficient unless the header is being overwritten somewhere later in your PHP code.
How are you verifying that the files are being served as text/html? If you call die() immediately after your call to header() is the right content-type served?
PHP FAQ
Originally Posted by Spad
Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
August 2nd, 2012, 10:29 AM
-
Originally Posted by E-Oreo
This by itself should be sufficient unless the header is being overwritten somewhere later in your PHP code.
How are you verifying that the files are being served as text/html? If you call die() immediately after your call to header() is the right content-type served?
I'm seeing the text/html part in live headers plugin for firefox, in firebug for firefox when making XHR calls to JSON and dynamic JavaScript files and in Chrome's equivilent console.
I've not tried an immediate die, but when you said "unless the header is being overwritten somewhere later in your PHP code" it got me thinking....my framework does do some header stuff towards the end of script execution....i shall check there first