Image optimizations for modern web
A method includes receiving, from a client device, an original user request to retrieve media content from a server, determining one or more media formats supported by the client device, identifying a formatted media content corresponding to a media format of the one or more media formats supported by the client device, generating a modified user request based on augmenting the original user request to include the formatted media content, and receiving, from the server, a response to the modified user request. In response to determining the response includes an error, the original user request is reconstructed, media content is retrieved from the media server using the reconstructed original user request, the retrieved media content is converted to one of the media formats supported by the client device, and the converted media content is sent to the client device.
1 . A method comprising:
receiving, by a computing system from a client device, an original user request to retrieve media content from a server;
determining, by the computing system, one or more media formats supported by the client device;
identifying, by the computing system, a formatted media content corresponding to a media format of the one or more media formats supported by the client device;
generating, by the computing system, a modified user request based on augmenting the original user request to include the formatted media content;
forwarding, by the computing system, the modified user request to the server;
receiving, by the computing system, a response to the modified user request from the server; and
in response to determining, by the computing system, that the response includes an error:
reconstructing, by the computing system, the original user request;
forwarding, by the computing system, the reconstructed original user request to the server;
receiving, by the computing system, media content retrieved by the server using the reconstructed original user request;
converting, by the computing system, the retrieved media content to one of the one or more media formats supported by the client device; and
sending, by the computing system, the converted media content to the client device.
2 . The method of claim 1 , further comprising:
in response to determining the response from the server does not include an error, sending, by the computing system, the response to the client device.
3 . The method of claim 1 , wherein receiving the original user request comprises receiving a Uniform Resource Locator (URL) that indicates the requested media content.
4 . The method of claim 1 , wherein determining the one or more media formats supported by the client device comprises determining if the client device supports one or more of an AV1 Image File (AVIF) format and a WebP format.
5 . The method of claim 1 , wherein:
identifying the formatted media content comprises identifying a destination Uniform Resource Locator (URL) of a media content having a format that is supported by the client device; and
generating the modified user request comprises replacing a URL in the original user request with the destination URL.
6 . The method of claim 5 , wherein reconstructing the original user request comprises replacing the destination URL with the URL in the original user request.
7 . The method of claim 1 , wherein converting the retrieved media content comprises converting the retrieved media content from a Joint Photographic Experts Group (JPEG) format or a Portable Network Graphics (PNG) format to one of an AV1 Image File (AVIF) format and a WebP format.
8 . The method of claim 1 , wherein, in response to determining the response includes the error, the method further comprises caching, by the computing system, the converted media content for subsequent reuse.
9 . The method of claim 1 , further comprising:
checking, by the computing system, a media cache for a formatted media content corresponding to the requested media content; and
in response to the formatted media content corresponding to the requested media content being stored in the media cache, sending, by the computing system, the formatted media content to the client device.
10 . The method of claim 1 , wherein converting the retrieved media content comprises resizing the media content based on a user profile.
11 . The method of claim 1 , wherein sending the converted media to the client device comprises resizing and/or scaling the media content based on requirements of the client device.
12 . A non-transitory computer readable medium containing instructions that, when executed, cause a processor of a computing system to execute processes comprising:
receiving, by the computing system from a client device, an original user request to retrieve media content from a server;
determining, by the computing system, one or more media formats supported by the client device;
identifying, by the computing system, a formatted media content corresponding to a media format of the one or more media formats supported by the client device;
generating, by the computing system, a modified user request based on augmenting the original user request to include the formatted media content;
forwarding, by the computing system, the modified user request to the server;
receiving, by the computing system, a response to the modified user request from the server; and
in response to determining, by the computing system, that the response includes an error:
reconstructing, by the computing system, the original user request;
forwarding, by the computing system, the reconstructed original user request to the server;
receiving, by the computing system, media content retrieved by the server using the reconstructed original user request;
converting, by the computing system, the retrieved media content to one of the one or more media formats supported by the client device; and
sending, by the computing system, the converted media content to the client device.
13 . The non-transitory computer readable medium according to claim 12 , wherein in response to determining the response from the server does not include an error, sending, by the computer system, the response to the client device.
14 . The non-transitory computer readable medium according to claim 12 , wherein:
determining the one or more media formats supported by the client device comprises determining if the client device supports one or more of an AV1 Image File (AVIF) format and a WebP format, and
converting the retrieved media content comprises converting the retrieved media content from a Joint Photographic Experts Group (JPEG) format or a Portable Network Graphics (PNG) format to one of the AV1 Image File (AVIF) format and the WebP format.
15 . The non-transitory computer readable medium according to claim 12 , wherein,
identifying the formatted media content comprises identifying a destination URL of a media content having a format that is supported by the client device; and
generating the modified user request comprises replacing a URL in the original user request with the destination URL.
16 . The non-transitory computer readable medium according to claim 12 , wherein in response to determining the response includes the error, the instructions further cause the processor to execute a process of caching the converted media content for subsequent reuse.
17 . The non-transitory computer readable medium according to claim 12 , wherein the instructions further cause the processor to execute processes of:
checking a media cache for a formatted media content corresponding to the requested media content; and
in response to the formatted media content corresponding to the requested media content being stored in the media cache, sending the formatted media content to the client device.
18 . A computing system comprising:
a processor; and
a memory coupled to the processor and storing a set of instructions that, when executed, cause the processor to execute processes of:
receiving, by the computing system from a client device, an original user request to retrieve media content from a server;
determining, by the computing system, one or more media formats supported by the client device;
identifying, by the computing system, a formatted media content corresponding to a media format of the one or more media formats supported by the client device;
generating, by the computing system, a modified user request based on augmenting the original user request to include the formatted media content;
forwarding, by the computing system, the modified user request to the server;
receiving, by the computing system, a response to the modified user request from the server; and
in response to determining, by the computing system, that the response includes an error:
reconstructing, by the computing system, the original user request;
forwarding, by the computing system, the reconstructed original user request to the server;
receiving, by the computing system, media content retrieved by the server using the reconstructed original user request;
converting, by the computing system, the retrieved media content to one of the one or more media formats supported by the client device; and
sending, by the computing system, the converted media content to the client device.
19 . A Content Delivery Network (CDN) comprising:
the computing system according to claim 18 ;
at least one client device; and
at least one server configured to store media content.
20 . The computing system of claim 18 , wherein,
the computing system receives the original user request from the client device by intercepting the original user request as it is sent from the client device to the server.