preg_replace(和其他)导致Windows上出现Javascript问题

I am stuck with a weird problem. I've never seen anything like that before and I can't find any similar cases to my problem. I am on Windows 7, PHP 5.5.x and Apache.

My framework is serving javascript by itself (e.g. with readfile(...)) . This approach allows me to translate and serve javascript files on the fly (duh!). For instance, if JS code contains smth like var msg="<translate>This string</translate>"; then, when it's being served by the framework, <translate> tags are translated with

preg_replace_callback('/<translate>(.*?)<\/translate>/i', $callback, $content);

Where $callback is the function that translates $content.

The $callback can be boiled down to this simple code (which still will cause JS to render improperly):

$callback = function($matches) {
    return $matches[1];
};

All in all it works well on Linux, but when I try running that on Windows, my Firefox refuses to interpret translated JS code!

Has anyone had any similar problems?

I've also tried preg_replace, preg_replace_callback and even str_replace just for fun. Any string replacement in JS code leads to errors on client side. Explicitly setting charset=utf-8 in Content-Type header doesnt help either.

I've realized it right after I stripped down everything and saw a Failed to load resource: net::ERR_CONTENT_LENGTH_MISMATCH message once again in Chrome. The problem was is that I was sending a Content-Length header (length was set to the filesize($file) before I translated my JS files. Hence the problem.

I am not sure why it works in Linux with (more or less) default settings for Apache, but it does not work well with Windows' Apache.

@dman2306 Thank you for the input!