PERF: Skip image placeholders when secure_media is enabled (#18247)
Secure media requests go through the app. In topics with many images, this makes it very easy to hit rate limiters. Skipping the low-res placeholders reduces the chance of this problem occuring.
This commit is contained in:
parent
09a434e2d8
commit
04e433d286
|
@ -17,9 +17,19 @@ function isLoaded(img) {
|
|||
|
||||
export function nativeLazyLoading(api) {
|
||||
api.decorateCookedElement(
|
||||
(post) =>
|
||||
(post) => {
|
||||
const siteSettings = api.container.lookup("service:site-settings");
|
||||
|
||||
forEachImage(post, (img) => {
|
||||
img.loading = "lazy";
|
||||
|
||||
if (siteSettings.secure_media) {
|
||||
// Secure media requests go through the app. In topics with many images,
|
||||
// this makes it very easy to hit rate limiters. Skipping the low-res
|
||||
// placeholders reduces the chance of this problem occuring.
|
||||
return;
|
||||
}
|
||||
|
||||
if (img.dataset.smallUpload) {
|
||||
if (!isLoaded(img)) {
|
||||
if (!img.onload) {
|
||||
|
@ -36,7 +46,8 @@ export function nativeLazyLoading(api) {
|
|||
img.style.setProperty("background-size", "cover");
|
||||
}
|
||||
}
|
||||
}),
|
||||
});
|
||||
},
|
||||
{
|
||||
onlyStream: true,
|
||||
id: "discourse-lazy-load-after-adopt",
|
||||
|
|
Loading…
Reference in New Issue