Wordpress tinymce.js parsed like php?

The TinyMCE editor on 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 learn 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 answer:

 <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 /> 

Other .js files are correctly extracted and executed. Turning off the W3TC does not matter. The problem exists in Firefox. It seems that the problem arose suddenly; I don’t know anything that I changed without even updating or installing / removing plugins.

Thanks in advance.

+6
source share
1 answer

This will not happen if PHP does not handle the request for the .js file.

Check the Apache2 conf file, and also check the conf.d files in the conf.d folder. Also check the .htaccess file. Find something like this in these files:

 AddHandler application/x-httpd-php .js 

This can happen in a block like this:

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

Some tutorials for setting up .htaccess and apache suggest using PHP to process .js files due to some tricks that this will allow you to do. The most common reason is to call the PHP GZIP file in zip compression of JS files. Unfortunately, using php to handle tiny_mce.js seems to interrupt Wordpress. PHP disables something in tiny_mce.js file - perhaps because it was minimized?

I ran into this exact problem and had to remove the php handler for .js files from my configuration. Actually, there was no need for this because my Apache was set up to write itself. I do not name the PHP file to make gzip. Relying on a PHP script to compress zip is really not the best way to do things (obviously because it creates problems like this!).

Hope this helps someone.

Readers may also find this post helpful: Caching issue using AddHandler / x-httpd-php "

I will also add that the arbitrary use of PHP to handle static files such as JS and CSS is not a good idea for performance reasons. You should never call a PHP handler unless the files are truly dynamic. Otherwise, you add unnecessary resource requirements to the server.

+4
source

Source: https://habr.com/ru/post/918225/


All Articles