I am developing one site in ror and I have done caching but its quit slow on loading due to images. Can you say me which are best possible ways to work out in ror to make my site fast. Or any gem which will help me out.
-
So have you tried to solve this yourself and ran into a problem? What performance did you get? Can you show some code? – aberna Feb 12 '15 at 06:53
-
possible duplicate: http://stackoverflow.com/questions/1156759/webrick-is-very-slow-to-respond-how-to-speed-it-up – shivam Feb 12 '15 at 06:53
-
https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/image-optimization – Brad Werth Feb 12 '15 at 06:58
1 Answers
Let's assume you're sure it's the images that are the issue. If so, your images should be served directly by your webserver (eg. nginx or apache) and RoR shouldn't have to be involved at all. Assuming that's the case, you can do a few things:
Ensure that the images are not sized bigger than they have to be displayed. For example, if your site shows the images at 300px by 300px, make sure you're not accidentally downloading a 5000px by 5000px version, and having the browser resize it. (If you're uploading images via an admin interface, a gem like Carrierwave or paperclip can help you resize the uploaded images.
When you create images, make sure you've created them in a suitable way for the web (eg. selecting the right type - jpg, gif, png-8, png-24, selecting the right quality, etc). Use something like Photoshop's 'Save for Web' feature.
Use a tool like ImageOptim (https://imageoptim.com/) to losslessly reduce image size
Use CSS wherever possible - eg, if you're using an image for a background gradient, or a round-bordered button with a glow effect on hover, don't. Use CSS.
Combine images into Sprites when suitable (Google that term if you're not familiar)
Rather than storing images on your own server, store them on something like Amazon S3. Or, use a CDN.
Caching. You mention you've done caching. Not sure specifically what you've done there, but ensure your browsers cache images for a reasonable amount of time (if you're using Ruby on Rails asset pipeline and fingerprinted images, browsers should be able to cache your images forever). Also ensure you're gzipping stuff that gets sent back to the browser.
Reduce the number of images on your page. If you've got a whole heap of images, your site will just be slow - no way around it. Even if the images are small, for each image on your page, a separate request needs to be sent to the server. The time adds up, and there's no way around this.

- 13,762
- 4
- 45
- 60
-
-
-
If your files are on S3 so caching is the only way, try Nginx S3 proxy for that. – Anatoly Mar 29 '15 at 00:42