Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I want .js files in some very specific folder to be rendered with PHP by Apache. Where can I set it, and how?

In other words: I want apache to deal with files with extension js, as if they are with extension php... but only in specific folder of /var/www

share|improve this question
    
This is confusing, please add more info on what you want to do. PHP is server side, .js is rendered client side. The Apache server never does anything with .js other than serving as a text file (with proper headers). –  Rich Homolka Jun 26 '11 at 16:28
    
Yes, I know, but afaik you can tell apache how to behave with every file extension. Now I need to define that behavior for very specific folder. –  David Jun 27 '11 at 7:01

2 Answers 2

up vote 1 down vote accepted

I think i know what you mean now. You want a js file to be sent to the client, but you want to process it as PHP so you can modify the js file before sending it to the client.

If so, try:

<Directory /var/www/somespecialjsfolder >
AddType application/x-httpd-php .js
</Directory>

You'll probably need to add PHP code to set mime-type to application/x-javascript on output of your js.

That said, this is probably a bad idea. You don't want to have to debug Javascript which is different for every client. Put all your client customizations in the js file, keep it consistent. Abstract things out with JQuery or equivalent.

share|improve this answer

What is the content of these .js files ? Is it PHP or JavaScript ?

Do be more precise: do you want Apache to read the contents of this files as PHP, because it is, only with an uncommon extension, or do you want Apache to process JavaScript instructions server-side ?

If it's the latter, I don't know of any simple way to do this. It would involve parsing the contents of the .js files, and rewrite this JavaScript in PHP, assuming it is code for which there is sense to execute it on the server...

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.