CSS/JavaScript changes not appearing in Vagrant

September 23, 2016

The past week we had this annoying issue of CSS and JavaScript changes not appearing when served from a Vagrant box. Clearing browser cache wouldn’t help but renaming the file did show the latest change. So, something else (if not the browser) appeared to «cache» the initial file and subsequent changes would not be picked up.

If not the browser then what?

Okay, the static files served by Nginx are first accessed by the guest OS through a VirtualBox shared folder. As per a very old «bug» it seems that the sendfile() function (enabled in Nginx) is not very friendly with the shared folder feature of VirtualBox Guest Additions.

While some people have resorted to using NFS for sharing files between host & guest machines; a quicker workaround is to turn off sendfile in Nginx.

sendfile off;

Put the above inside the http block to apply to all your virtual hosts or just within the concerned vhost’s server block.

The sendfile() system call in the Linux kernel allows data to be copied from one file descriptor to another file descriptor; unlike traditionally requiring more system calls for reading and writing. It is actually well documented at tdlp.org.

Disabling sendfile has a performance downside but let’s just say it is acceptable for the local development environment.