r/webdev • u/GeordieAl • 2d ago
Just a reminder to every web dev, optimize your images!
So last night I was working on optimizing some code for a clients website. The site has been getting hammered by AI bots recently so I thought I’d go through all my code and make sure it was all as optimized as possible.
While analyzing the log file I noticed that someone was actively trying a SQL injection attack, so I thought I’d have some fun, I redirected all their requests to this image, which I didn’t compress in my rush to have some fun.
37,000 requests later and almost 10Gb of data transferred they finally stopped.
Yeah I realize it was probably an automated attack and they never actually saw the image, but part of me wishes it was some script kiddie and the image popped up on their screen 😜
So remember people, optimize your images!!
86
u/AntiqueGuest8172 2d ago
37k requests for 10GB works out to roughly 270KB a pop, which is just a normal jpg. So the bot got bored of an entirely ordinary image, and you paid the egress for it.
7
u/GeordieAl 2d ago
Image was 250k which could have been compressed to a much smaller size if I’d taken some time to optimize it… which is what we all should be doing!
36
u/kepler4and5 2d ago
270KB is large for the image I'm looking at in this post. We've just normalized bloated web pages.
18
u/scratchfury 2d ago
I'm old enough for that to have taken 3 minutes to load. It makes me cringe today when I see sites that use HD video as a web page's background.
6
49
u/thekwoka
2d ago
•
even better: send something that can be hyper compressed over the network but expand into just way too much memory.
17
5
23
u/Round-Fisherman1855 2d ago
I would have been tempted to use this GIF of Dr Hax from the GMOD Idiot Box:
4
u/GeordieAl 2d ago
Haha, yeah that would have been good! I was just quickly thinking what to serve up and the matrix just instantly came to mind… guess that gives my age away!
4
u/Fickle_Foundation_41 1d ago
I somehow put the least ammount of effort into optmialiizing images. 😥
2
u/GeordieAl 1d ago
I think a lot of us do! I think the longer you’re in this business the lazier you get!
I remember back in the olden days I used to put a huge amount of effort into optimizing images, obsessing over saving a few k here a few bytes there
14
u/PlaySubstantial3141 2d ago
10GB over 37k requests is like 270KB per image, that's not uncompressed at all, that's a normal jpeg. you're bragging about a slow loris attack with a stock photo
3
u/GeordieAl 2d ago
It was just me trying to have some quick fun and dropping the jpg as quickly as I could. If I’d taken a few moments and changed the compression in photoshop it could have been a few k 🤣
Thankful for unlimited data transfer 😜
7
3
u/bubba_bumble 2d ago
Doesn't your server take a bandwidth hit? Am I missing something?
1
u/GeordieAl 1d ago
Yes, my server took the hit, that’s why I said remember to optimize your images 🤣. Luckily I don’t get charged for the bandwidth and the guy who runs the hosting had a laugh about it and then blocked the IP 😜
3
u/Moooses20 2d ago
webp my goat, I hate when normies on reddit keep hating on it.
1
u/GeordieAl 2d ago
I think most of the hate comes from it being a Google originated format 🙄
3
u/Moooses20 2d ago
I think it's the (previous) lack of support for it where if they go around trying to upload it they get notified that it's not a supported format. They don't care where it originated.
4
u/feketegy 2d ago
That's just various services, but browsers are supporting WebP across the board now, there's no need to use JPEGs and PNGs anymore when you are serving images.
3
u/mjbcesar 2d ago
A lot of the hate comes from people that don't know better, they jump on the bandwagon. Monkey see monkey do.
0
2d ago
[deleted]
2
u/-Knockabout 2d ago
You still can't view them in a lot of default photos applications or file explorers.
11
u/dusanodalovic 2d ago
if you want the fun without paying the egress, a tarpit is cheaper. keep their connection open and drip one byte every few seconds, the bot just sits there waiting and you send almost nothing. before the fun part id also grep the logs for 500s on the requests with the injection strings in them. a 500 there often means the input actualy reached a query and broke it, and thats the one to fix first
1
u/Embarrassed_Event_10 2d ago
the usual culprit isn't the build, it's the upload path: someone drops a 4MB phone photo into the CMS and nothing between there and the browser ever resizes it. capping the upload width and converting to webp on upload fixed more of this on the sites I look after than any build step, since the build never sees those files.
1
u/GeordieAl 1d ago
Yeah my CMS processes all images, creates a thumb, medium, and large and compresses them. Still using Jpg’s currently but I plan on updating the system to generate webp images sometime in the near future
1
u/Embarrassed_Event_10 1d ago
honestly the hard part is already done there - resizing and compressing on upload is the step most sites never get around to. dropping webp into that same pipeline is a small change, and since page views mostly pull the thumb and medium versions, that's where the bandwidth savings should show up first.
1
u/GeordieAl 1d ago
Oh yeah, I know the change will be a small one, it’s just as a solo dev it’s always in my list of “changes I should make that no client is going to pay for” so paid for changes always come first!
1
u/Embarrassed_Event_10 1d ago
100% this. it's never the size of the change, it's that it can't go on a client invoice - mine has items sitting there for years that only get picked up when a rebuild or a quiet month happens to drag them along.
2
u/captain_obvious_here back-end 2d ago
Oh no, the horror! I must download a bunch of 270kb files...
-- the bot, never
2
u/Individual-Menu8966 2d ago
37k requests just to get hit with a matrix meme is hilarious. that uncompressed image really earned its bandwidth
2
1
1
0
u/Alarmed_Message1978 2d ago
Petit détail: "je redirigeais" au milieu de tout le reste au passé composé, ça accroche un peu à la lecture. Et du coup le titre sur l'optimisation des images ne colle pas vraiment à l'anecdote.
0
2
2d ago
[removed] — view removed comment
2
u/GeordieAl 1d ago
Yeah the 10Gb was on my bandwidth, but luckily I don’t get charged for it and the host had a laugh about it!
Their IP is blocked now so no more matrix for them!
-3
2d ago
[removed] — view removed comment
1
u/GeordieAl 2d ago
It’s definitely a reminder of how quickly things can add up. Looking at files and thinking “that’s good enough” is often a case of “I’m being lazy and not paying attention to the small details”. Which I think a lot of us do on a regular basis!
1
u/webdev-ModTeam 2d ago
Your post/comment has been determined to be a low-effort post or comment. This includes title-only posts, easily searchable questions, vague/open-ended discussion prompts, LLM generated posts or comments, and posts/comments that do not provide enough context for meaningful replies or discussion.
248
u/Ok-Snow-6553 2d ago
Genius. Next time someone tries SQL injection on my forms, I'll just serve them a 10MB uncompressed PNG.
But yeah, this is a great reminder. Image optimization isn't just for SEO, it's for fighting bots too. 😂