Lately I’m playing with the Nginx webserver. Nginx is a free, open-source, high-performance HTTP server hosting 7.5% of all webservers on the internet (that’s 20.5M webservers).
CakePHP plugin assets are served through PHP, which makes it obviously slower than serving it without invoking PHP. I found a little solution that speeds up every plugin asset by ~ 60ms. So when you have lots of images, css and javascript files in your plugin, you can speed up your page load time by several seconds!
One of the great benefits is the freedom and flexibility of the configuration files, so I played a bit with the ‘try_files functionality‘ which results in amazing performance improvements. Of course I’m willing to share it, feel free to comment/critize it;
You can find (and fork) my full configuration example in my github repo:
https://github.com/Lennaert/Lennaerts-Snippets
For a full Nginx / PHP / CakePHP setup I could truly recommend the blog post of Kevin van Zonneveld and Chris Hartjes, I learned a lot from them!
3 Responses to CakePHP Performance: Rewrite plugin assets in Nginx
this only works when you have assets in plugins i assume? you can also put assets in the normal webroot like:
/webroot/img/plugin/image.jpg
reply/webroot/js/plugin/javascript.js
@Rodriqo: I understand what you try to do, and it’s of course more easy in case you don’t have access to config files.
I think the benefits of using assets in plugins (and the reason why they made it like this), is that you can use plugins in all your projects without thinking of all the js/img/css files.
You can package your plugin and distribute it in seconds.
And yes, this only works for assets in plugins, since `normal` webroot files are already directly served by nginx.
Thanks for commenting!
replyAdd a comment