refinery / refinerycms-page-images

Adds an images tab to your pages so you can format a group of images really nicely on the frontend
104 stars 120 forks source link

Slow page loading times #143

Open Pjero opened 7 years ago

Pjero commented 7 years ago

I've implemented a gallery on one of my projects using the code from the readme and the page load times in production on the gallery page are incredibly slow. I only need a gallery with 10 images max, but it is slow with just 4.

The view code:

 <%- @page.images.each do |image| %>
      <figure>
        <a href=<%= image.thumbnail(geometry: "1024x").url %> data-size=<%= "#{image.thumbnail(geometry: "1024x").width}x#{image.thumbnail(geometry: "1024x").height}" %> data-turbolinks="false">
          <%= image_fu image, '283x223#', alt: "Image description", itemprop: "thumbnail" %>
        </a>
        <figcaption itemprop="caption description"><%=image.title %></figcaption>

      </figure>
  <% end %>

I've tried it on another page (on a different and faster server) with the same results.

stefanspicer commented 7 years ago

We've had problems with cropping images being slow and using more memory that we'd like (taking our server out). Here's our current solution to deal with this:

routes.rb: get '/system/images/:job/:filename', constraints: lambda { |request| request.params[:filename] !~ /^image.[\w]+{2,5}/ }, to: redirect { |params, request| "/system/images/#{params[:job]}/image#{Rack::Mime::MIME_TYPES.invert[request.format.to_str]}#{'?' + request.query_string if request.query_string.present?}" }

refinery/images/dragonfly.rb: app_images.configure do [...] if Refinery::Images.dragonfly_use_local_cache before_serve do |job, env| job.to_file("#{Rails.root}/public#{app_images.server.url_for(job).sub(/\?.*$/, '')}.#{job.ext}") end end end

This saves the images in /public dir for apache or nginx to serve up directly next time and essentially caches it forever. We don't have a problem with caching forever because we don't allow editing of images. Every uploaded image is a new Refinery::Image in the DB. The extra route above just stops someone from fetching abcdefghijkl.jpg, abcdefghijk.jpg, abcdefghij.jpg, abcdefghi.jpg, abcdefgh.jpg, abcdefg.jpg, abcdef.jpg, abcd.jpg, abc.jpg (we had someone take out the server with convert processes once in this way)