0

YouTube videos have different resolution default thumbnails to use. We use the "default" version (ie: http://img.youtube.com/vi/UNIQUECODE/default.jpg) to preview youtube videos before showing them.

The problem is that Google PageSpeed then dings the page as having a non-compressed image. (ie: Compressing http://img.youtube.com/vi/UNIQUECODE/default.jpg could save 1.1KiB (23% reduction). ).

Is there anyway to call their API and get a compressed image to show?

danwood
  • 1,512
  • 1
  • 10
  • 27
Stech
  • 33
  • 7
  • Considering how much Google as a company has pushed for optimizing your web page delivery, I'm surprised that this has escaped notice. According to WebPageTest.org, images need to be made progressive JPEG as well as being optimized/compressed. – danwood Apr 10 '18 at 15:14

1 Answers1

0

There are only the default options offered, they don't have a processing option. One possiblity is a 3rd-party compression service like TinyPNG. Their developer API lets you remotely compress an image:

Features: "You can either upload images directly or specify a URL to the image you want to compress."

A POST request using JSON will compress the Youtube image on TinyPNG's server:

POST /shrink HTTP/1.1
Host: api.tinify.com
Authorization: Basic YXBpOmFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6MDEyMzQ1
Content-Type: application/json
{
  "source": {
    "url": " http://img.youtube.com/vi/UNIQUECODE/default.jpg)"
  }
}

The (JSON) response would give you a new compressed image link to use instead of the one from Youtube.

Bman70
  • 743
  • 5
  • 11