#1
  1. Mad Scientist
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2007
    Location
    North Yorkshire, UK
    Posts
    3,661
    Rep Power
    4124

    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.
    I said I didn't like ORM!!! <?php $this->model->update($this->request->resources[0])->set($this->request->getData())->getData('count'); ?>

    PDO vs mysql_* functions: Find a Migration Guide Here

    [ Xeneco - T'interweb Development ] - [ Are you a Help Vampire? ] - [ Read The manual! ] - [ W3 methods - GET, POST, etc ] - [ Web Design Hell ]
  2. #2
  3. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,316
    Rep Power
    7170
    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
  4. #3
  5. Mad Scientist
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2007
    Location
    North Yorkshire, UK
    Posts
    3,661
    Rep Power
    4124
    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
    I said I didn't like ORM!!! <?php $this->model->update($this->request->resources[0])->set($this->request->getData())->getData('count'); ?>

    PDO vs mysql_* functions: Find a Migration Guide Here

    [ Xeneco - T'interweb Development ] - [ Are you a Help Vampire? ] - [ Read The manual! ] - [ W3 methods - GET, POST, etc ] - [ Web Design Hell ]

IMN logo majestic logo threadwatch logo seochat tools logo