⚠️ This article is outdated: Don’t use jQuery. Also, this JS technique does not work well when server side rendering.
Responsive images are pretty intuitive; apply max-width: 100%
and voila. But what to do about those pesky iframes (video embeds!) whose height does not remain in ratio to width when responding down? The most common technique you will come across dates back years and involves wrappers styled to preserve a hard-coded intrinsic aspect ratio (typically 16:9). Most of the popular scripts such as fitvids.js utilize this technique.
This approach sucks for few reasons:
- Wrappers may not play nice with your current setup. Perhaps your videos are added, sized and positioned via a CMS WYSIWYG.
- Is ~75 lines of jQuery really necessary?