Scott
Scott

Reputation: 86

.php Javascript File

My question is - are there any significant drawbacks to using a .php file and telling the browser to interpret it as Javascript?

Once it's rendered by the server, the content of the .php file would be entirely Javascript, however, tweaked slightly allowing for user permissions etc.

My main reasoning is that I don't want certain administrative functions to be at all visible to standard users (ie. those with prying eyes looking through the Javascript code).

I've seen here (Including php file as JS) that it IS POSSIBLE (technically) to achieve this, however it seems a little 'botchy' - has anyone had any experience with this practice?

Upvotes: 0

Views: 52

Answers (1)

cantelope
cantelope

Reputation: 1165

There are no significant drawbacks. Indeed this is one off the main purposes of PHP - to render text and code to be sent to the browser. There's not much difference between using PHP to echo out a few lines of javascript, and just having the whole file be javascript. The only benefit to using a PHP file for javascript would be the ability to embed PHP code, which is of course invisible to the user.

Upvotes: 1

Related Questions