discourse/spec
David Taylor d0243f741e
UX: Use dominant color as image loading placeholder (#18248)
We previously had a system which would generate a 10x10px preview of images and add their URLs in a data-small-upload attribute. The client would then use that as the background-image of the `<img>` element. This works reasonably well on fast connections, but on slower connections it can take a few seconds for the placeholders to appear. The act of loading the placeholders can also break or delay the loading of the 'real' images.

This commit replaces the placeholder logic with a new approach. Instead of a 10x10px preview, we use imagemagick to calculate the average color of an image and store it in the database. The hex color value then added as a `data-dominant-color` attribute on the `<img>` element, and the client can use this as a `background-color` on the element while the real image is loading. That means no extra HTTP request is required, and so the placeholder color can appear instantly.

Dominant color will be calculated:
1. When a new upload is created
2. During a post rebake, if the dominant color is missing from an upload, it will be calculated and stored
3. Every 15 minutes, 25 old upload records are fetched and their dominant color calculated and stored. (part of the existing PeriodicalUpdates job)

Existing posts will continue to use the old 10x10px placeholder system until they are next rebaked
2022-09-20 10:28:17 +01:00
..
fabricators UX: Use dominant color as image loading placeholder (#18248) 2022-09-20 10:28:17 +01:00
fixtures FEATURE: Add support for case-sensitive Watched Words (#17445) 2022-08-02 10:06:03 +02:00
helpers DEV: Use proper wording for contexts in specs 2022-08-04 11:05:02 +02:00
import_export DEV: Use proper wording for contexts in specs 2022-08-04 11:05:02 +02:00
initializers Add RSpec 4 compatibility (#17652) 2022-07-28 10:27:38 +08:00
integration DEV: Use proper wording for contexts in specs 2022-08-04 11:05:02 +02:00
integrity DEV: Use proper wording for contexts in specs 2022-08-04 11:05:02 +02:00
jobs FIX: Don't delete previous messages when we're inside the `sent_recently` window. (#18239) 2022-09-13 12:43:24 -03:00
lib UX: Use dominant color as image loading placeholder (#18248) 2022-09-20 10:28:17 +01:00
mailers DEV: Use proper wording for contexts in specs 2022-08-04 11:05:02 +02:00
models UX: Use dominant color as image loading placeholder (#18248) 2022-09-20 10:28:17 +01:00
multisite DEV: Use proper wording for contexts in specs 2022-08-04 11:05:02 +02:00
requests UX: Use dominant color as image loading placeholder (#18248) 2022-09-20 10:28:17 +01:00
script/import_scripts DEV: Use proper wording for contexts in specs 2022-08-04 11:05:02 +02:00
serializers FEATURE: anonymous sidebar categories and tags (#18038) 2022-08-23 16:20:46 +08:00
services FIX: Create single notification per post and user (#18091) 2022-09-01 16:07:18 +03:00
support DEV: Use proper wording for contexts in specs 2022-08-04 11:05:02 +02:00
tasks FEATURE: Create upload_references table (#16146) 2022-06-09 09:24:30 +10:00
views Add RSpec 4 compatibility (#17652) 2022-07-28 10:27:38 +08:00
rails_helper.rb DEV: Apply Rails 6.1 defaults 2022-05-24 17:13:44 +02:00
regenerate_swagger_docs DEV: Add API docs for uploads and API doc watcher (#15387) 2021-12-23 08:40:15 +10:00
swagger_helper.rb DEV: Fix openapi definition logo URL (#17038) 2022-06-08 13:10:20 +01:00