Zend Server "Caching" of JS and CSS files

1.6k Views Asked by At

I'm running Zend Server in a CentOS VM on Vitrualbox and I'm having a problem with linked JS and CSS assets being "cached". I say "cached" because they aren't, in the true sense, being cached, but rather when I add content to a JS or CSS file they become corrupted and the changes do not appear. Instead the file is appended with a bunch of bad characters eg.

layout.phtml (zend framework template)

$this->headScript()->appendFile ('/js/admin/product.js', 'text/javascript' );

This renders:

<script type="text/javascript" src="/js/admin/product.js"></script>  

products.js

        //re-add scrolling handles
        scrollThumbs.reSortThumbs(ul);
        product.moveFileInput(ul);
    };
};��������������������������������������������������

If I remove content from the JS or CSS file the result is an incomplete file and not the addition of bad characters as outlined above.

I've turned off all forms of Zend caching and even turned off Zend Optimizer. I've deleted browser cache and tried several browsers.

I have ssh'd into the server and double checked the file and it is perfectly formatted and contains the changes. I've tried restarting Zend Server (/usr/local/zend/bin/zendctl.sh restart) and Apache (service httpd restart)

The only way to fix it is to restart the entire OS (reboot). Interestingly, if I remove the changes, it goes back to working correctly. I can only assume that there is some form of caching happening somewhere on the server side.

3

There are 3 best solutions below

0
On BEST ANSWER

It turns out that it is a Virtualbox shared folder issue and not one uniquely related to Zend Server, but Apache in general.

The fix came from Shared folder in VirtualBox for Apache

Add EnableSendfile off to your vhost file eg.

<VirtualHost *:80>
    DocumentRoot "/mnt/your/shared/dir"
    ServerName Default

    <Directory "/mnt/your/shared/dir/public">
        EnableSendfile off
        Options FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>
1
On

It is because you have a browser cache turned on and the file name stays the same. This can be avoided by using md5_file() on you scripts and saving this to cookies, and on each request check if the cookie changed - in this case you will be able to manage cases when your front-end files are changed.

0
On

I tried the EnableSendfile off thing but it does not work on my Centos virtual machine with ZendServer. So I moved to my ubuntu virtual machine with apache installed manually (without ZendServer) and it worked perfectly. What seems to me, is that it is a issue on ZendServer, at least on ZendServer configuration.