Vagrant Static File Caching

 Jan 3, 2013

Over recent months I’ve been using Vagrant and virtualised development environments.

The ease of setup and being able to exactly mirror the final deploy environment from a OS/Software perspective is, I think, invaluable

However, one little thing has been bugging me over the time I’ve been working with Vagrant.

Updating JavaScript files in the shared directory and then refreshing a page in the browser had the oddest effect.

Rather than my changes being seen, the Javascript file I had just edited had become corrupted, and when viewed in the browser, had a number of unicode error symbols (the square with ?) at the end of the file instead of my actual edit. The number of symbols always matched the number of characters in my edit though.

After searching numerous times in vain, I finally found the solution, which I’ve reproduced here, but linked to the original source and the stack overflow thread so proper credit is given to the people who found/solved this issue

Basically there is an issue with Vagrant and static file serving via sendfile(), which needs to be disabled in whichever web server you are using.

Apache: EnableSendfile off
nginx: sendfile: off

1 StackOverflow 2 Google Groups