Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress tinymce.js being parsed as PHP?

The TinyMCE editor in my WordPress "Edit Post" page seems to be broken. Chrome console shows:

Resource interpreted as Script but transferred with MIME type text/html: "http://mysite.com/wp-includes/js/tinymce/langs/wp-langs-en.js?ver=349-20805". post.php:62
Resource interpreted as Script but transferred with MIME type text/html: "http://mysite.com/wp-includes/js/tinymce/tiny_mce.js?ver=349-20805". post.php:62
Uncaught SyntaxError: Unexpected token <          tiny_mce.js:1
Uncaught ReferenceError: tinyMCE is not defined   wp-langs-en.js:1
Uncaught ReferenceError: tinymce is not defined   post.php:1180

If I examine tinymce.js in the Chrome Developer Tools, I see these response headers:

Cache-Control:public, must-revalidate, proxy-revalidate
Connection:close
Content-Type:text/html
Date:Sat, 16 Jun 2012 01:40:42 GMT
Pragma:public
Server:Apache
Transfer-Encoding:chunked
Vary:Accept-Encoding
X-Powered-By:PHP/5.2.17, W3 Total Cache/0.9.2.4

And this response:

<br />
<b>Parse error</b>:  syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in <b>/home/mysite/public_html/wp-includes/js/tinymce/tiny_mce.js</b> on line <b>1</b><br />

Various other .js files are being properly retrieved and executed. Turning W3TC off makes no difference. Problem exists in Firefox, too. The problem seems to have cropped up all of a sudden; I'm not aware of anything that I've changed, not even updating or installing/uninstalling plugins.

Thanks in advance.

like image 470
wwninja Avatar asked Jun 16 '12 01:06

wwninja


Video Answer


1 Answers

This would not be happening unless PHP is handling the .js file request.

Check your Apache2 conf file and also check any conf.d files in the conf.d folder. Also check your .htaccess file. In those files look for something like this:

AddHandler application/x-httpd-php .js

It might occur in a block like this:

<FilesMatch ".js$">
AddHandler application/x-httpd-php .js
php_value default_mimetype "text/javascript"
</FilesMatch>

Some .htaccess and apache configuration tutorials suggest using PHP to handle .js files because of some tricks it'll let you do. The most common reason is for calling a PHP GZIP file to ZIP Compress the JS files. Unfortunately, using php to handle tiny_mce.js seems to break Wordpress. PHP is tripping on something in the tiny_mce.js file -- perhaps because its minified?

I ran into this exact problem and had to remove the php handler for .js files from my config. There was actually no need for it because my Apache is configured to do zipping on its own. I'm not calling a PHP file to do the gzip. Relying on a PHP script for zip compression really isn't the best way to be doing things (obviously because it creates problems like this one!).

Hope this helps someone.

Readers might also find this post useful: Caching problem using "AddHandler application/x-httpd-php"

I will also add that arbitrarily using PHP to handle static files like JS and CSS is not a good idea for performance reason. You shouldn't ever call a PHP handler unless the files are truly dynamic. Otherwise you're adding unnecessary resource requirements to the server.

like image 86
JamesHoux Avatar answered Sep 25 '22 08:09

JamesHoux