What's an easy way to detect a file has changed and update it automatically?
For example if I have a js/css file that I just uploaded, I'd like the server to detect I uploaded new js/css files and minify them automatically right then and there.
EDIT: I've tried minifying at run time and found out it's not efficient. It's interesting to note, that the file was minified for anyone requesting the file which was an overhead in itself and it was actually faster to not minify the file for delivery.
Ideally, the file should be minified within a few seconds of upload. Instead of a constantly polling system, is there an event based system out there that I could look into?
EDIT: I used mikhailov answer and added the following to the incron file:
/var/www/laravel/public/js/main.js IN_MODIFY yui-compressor -o /var/www/laravel/public/js/main.min.js /var/www/laravel/public/js/main.js
Inotify is a recommended pattern to get notified re file system events (file created, modified or deleted), what Wikipedia says:
Inotify (inode notify) is a Linux kernel subsystem that acts to extend filesystems to notice changes to the filesystem, and report those changes to applications.
See the similar use case: how to get notified of files being copied over rsync.