A few months ago I wrote about how combining the picture element module with the breakpoints module can help you manage images in a responsive Drupal 7 website more efficiently. As a follow up, I wanted to write about how Responsive Images has evolved within the Drupal ecosystem. This time however, the focus will be on Drupal 8— though most of what I will cover also applies to Drupal 7 with some minor differences.
There are two noticeable changes in Drupal 8 related to Responsive Images
- The picture element module is now called Responsive Images
- Both Responsive Images and the Breakpoints module are part of D8’s core (they are contributed modules in D7).
In earlier versions of the Responsive Images module (D8), and Picture module (D7), the only option for serving different images to different devices was to use the media attribute, which meant using media queries for detecting the device size. Although this works pretty well, the device’s size alone should not be the only criteria for serving images. The scenario that always comes to mind for this technique is that if I am using a laptop with a poor or unreliable wifi connection, I will still be served a large or high resolution image because my screen size is large. Wouldn’t it be nice to be able to detect other conditions when determining which image to serve to a device? Conditions such as connection speed, viewport size and screen density? Even better, wouldn’t it be nice if you could provide the browser with information about your images that normally would be unknown to the browser?
One of the biggest issues with images is the fact that the browser does not know the size or rendering information in relation to the viewport until the images, CSS or JS are fully loaded. Browsers can’t know anything about a website that they haven’t loaded yet. But they’re constantly aware of the environment they’re rendering within: the size of the viewport, the resolution of the user’s screen, that kind of thing. The idea of media queries is this: let web developers do specific things for specific environments. If the viewport is wider than a thousand pixels, then show the sidebar to the left. Otherwise, push it below our main content. If the user’s screen is retina, then use a big image. Otherwise, use a smaller one.
When using media queries alone, we are still telling the browser what image to serve based on the device size. It’s time we provide the browser with options and let it make the decision.
Identifying the gap between what the browser knows and doesn’t know at time of rendering:
Variables | by the author when he or she is writing the code? | Known by the browser when it’s loading the page? |
viewport dimensions | no | yes |
image size relative to the viewport | yes | no |
screen density | no | yes |
source files’ dimensions | yes | no |
As you can see from the table above, the browser is aware of viewport dimensions as well as screen density. However, the browser is not aware of how large images need to be rendered in relation to the viewport, or the actual physical file dimensions.
Learn More 1501
Learn More 1502
Learn More 1503
Learn More 1504
Learn More 1505
Learn More 1506
Learn More 1507
Learn More 1508
Learn More 1509
Learn More 1510
Learn More 1511
Learn More 1512
Learn More 1513
Learn More 1514
Learn More 1515
Learn More 1516
Learn More 1517
Learn More 1518
Learn More 1519
Learn More 1520
Learn More 1521
Learn More 1522
Learn More 1523
Learn More 1524
Learn More 1525
Learn More 1526
Learn More 1527
Learn More 1528
Learn More 1529
Learn More 1530
Learn More 1531
Learn More 1532
Learn More 1533
Learn More 1534
Learn More 1535
Learn More 1536
Learn More 1537
Learn More 1538
Learn More 1539
Learn More 1540
Learn More 1541
Learn More 1542
Learn More 1543
Learn More 1544
Learn More 1545
Learn More 1546
Learn More 1547
Learn More 1548
Learn More 1549
Learn More 1550
Learn More 1551
Learn More 1552
Learn More 1553
Learn More 1554
Learn More 1555
Learn More 1556
Learn More 1557
Learn More 1558
Learn More 1559
Learn More 1560
Learn More 1561
Learn More 1562
Learn More 1563
Learn More 1564
Learn More 1565
Learn More 1566
Learn More 1567
Learn More 1568
Learn More 1569
Learn More 1570
Learn More 1571
Learn More 1572
Learn More 1573
Learn More 1574
Learn More 1575
Learn More 1576
Learn More 1577
Learn More 1578
Learn More 1579
Learn More 1580
Learn More 1581
Learn More 1582
Learn More 1583
Learn More 1584
Learn More 1585
Learn More 1586
Learn More 1587
Learn More 1588
Learn More 1589
Learn More 1590
Learn More 1591
Learn More 1592
Learn More 1593
Learn More 1594
Learn More 1595
Learn More 1596
Learn More 1597
Learn More 1598
Learn More 1599
Learn More 1600
Learn More 1601
Learn More 1602
Learn More 1603
Learn More 1604
Learn More 1605
Learn More 1606
Learn More 1607
Learn More 1608
Learn More 1609
Learn More 1610
Learn More 1611
Learn More 1612
Learn More 1613
Learn More 1614
Learn More 1615
Learn More 1616
Learn More 1617
Learn More 1618
Learn More 1619
Learn More 1620
Learn More 1621
Learn More 1622
Learn More 1623
Learn More 1624
Learn More 1625
Learn More 1626
Learn More 1627
Learn More 1628
Learn More 1629
Learn More 1630
Learn More 1631
Learn More 1632
Learn More 1633
Learn More 1634
Learn More 1635
Learn More 1636
Learn More 1637
Learn More 1638
Learn More 1639
Learn More 1640
Learn More 1641
Learn More 1642
Learn More 1643
Learn More 1644
Learn More 1645
Learn More 1646
Learn More 1647
Learn More 1648
Learn More 1649
Learn More 1650
Learn More 1651
Learn More 1652
Learn More 1653
Learn More 1654
Learn More 1655
Learn More 1656
Learn More 1657
Learn More 1658
Learn More 1659
Learn More 1660
Learn More 1661
Learn More 1662
Learn More 1663
Learn More 1664
Learn More 1665
Learn More 1666
Learn More 1667
Learn More 1668
Learn More 1669
Learn More 1670
Learn More 1671
Learn More 1672
Learn More 1673
Learn More 1674
Learn More 1675
Learn More 1676
Learn More 1677
Learn More 1678
Learn More 1679
Learn More 1680
Learn More 1681
Learn More 1682
Learn More 1683
Learn More 1684
Learn More 1685
Learn More 1686
Learn More 1687
Learn More 1688
Learn More 1689
Learn More 1690
Learn More 1691
Learn More 1692
Learn More 1693
Learn More 1694
Learn More 1695
Learn More 1696
Learn More 1697
Learn More 1698
Learn More 1699
Learn More 1700
Learn More 1701
Learn More 1702
Learn More 1703
Learn More 1704
Learn More 1705
Learn More 1706
Learn More 1707
Learn More 1708
Learn More 1709
Learn More 1710
Learn More 1711
Learn More 1712
Learn More 1713
Learn More 1714
Learn More 1715
Learn More 1716
Learn More 1717
Learn More 1718
Learn More 1719
Learn More 1720
Learn More 1721
Learn More 1722
Learn More 1723
Learn More 1724
Learn More 1725
Learn More 1726
Learn More 1727
Learn More 1728
Learn More 1729
Learn More 1730
Learn More 1731
Learn More 1732
Learn More 1733
Learn More 1734
Learn More 1735
Learn More 1736
Learn More 1737
Learn More 1738
Learn More 1739
Learn More 1740
Learn More 1741
Learn More 1742
Learn More 1743
Learn More 1744
Learn More 1745
Learn More 1746
Learn More 1747
Learn More 1748
Learn More 1749
Learn More 1750
Learn More 1751
Learn More 1752
Learn More 1753
Learn More 1754
Learn More 1755
Learn More 1756
Learn More 1757
Learn More 1758
Learn More 1759
Learn More 1760
Learn More 1761
Learn More 1762
Learn More 1763
Learn More 1764
Learn More 1765
Learn More 1766
Learn More 1767
Learn More 1768
Learn More 1769
Learn More 1770
Learn More 1771
Learn More 1772
Learn More 1773
Learn More 1774
Learn More 1775
Learn More 1776
Learn More 1777
Learn More 1778
Learn More 1779
Learn More 1780
Learn More 1781
Learn More 1782
Learn More 1783
Learn More 1784
Learn More 1785
Learn More 1786
Learn More 1787
Learn More 1788
Learn More 1789
Learn More 1790
Learn More 1791
Learn More 1792
Learn More 1793
Learn More 1794
Learn More 1795
Learn More 1796
Learn More 1797
Learn More 1798
Learn More 1799
Learn More 1800
Learn More 1801
Learn More 1802
Learn More 1803
Learn More 1804
Learn More 1805
Learn More 1806
Learn More 1807
Learn More 1808
Learn More 1809
Learn More 1810
Learn More 1811
Learn More 1812
Learn More 1813
Learn More 1814
Learn More 1815
Learn More 1816
Learn More 1817
Learn More 1818
Learn More 1819
Learn More 1820
Learn More 1821
Learn More 1822
Learn More 1823
Learn More 1824
Learn More 1825
Learn More 1826
Learn More 1827
Learn More 1828
Learn More 1829
Learn More 1830
Learn More 1831
Learn More 1832
Learn More 1833
Learn More 1834
Learn More 1835
Learn More 1836
Learn More 1837
Learn More 1838
Learn More 1839
Learn More 1840
Learn More 1841
Learn More 1842
Learn More 1843
Learn More 1844
Learn More 1845
Learn More 1846
Learn More 1847
Learn More 1848
Learn More 1849
Learn More 1850
Learn More 1851
Learn More 1852
Learn More 1853
Learn More 1854
Learn More 1855
Learn More 1856
Learn More 1857
Learn More 1858
Learn More 1859
Learn More 1860
Learn More 1861
Learn More 1862
Learn More 1863
Learn More 1864
Learn More 1865
Learn More 1866
Learn More 1867
Learn More 1868
Learn More 1869
Learn More 1870
Learn More 1871
Learn More 1872
Learn More 1873
Learn More 1874
Learn More 1875
Learn More 1876
Learn More 1877
Learn More 1878
Learn More 1879
Learn More 1880
Learn More 1881
Learn More 1882
Learn More 1883
Learn More 1884
Learn More 1885
Learn More 1886
Learn More 1887
Learn More 1888
Learn More 1889
Learn More 1890
Learn More 1891
Learn More 1892
Learn More 1893
Learn More 1894
Learn More 1895
Learn More 1896
Learn More 1897
Learn More 1898
Learn More 1899
Learn More 1900
Learn More 1901
Learn More 1902
Learn More 1903
Learn More 1904
Learn More 1905
Learn More 1906
Learn More 1907
Learn More 1908
Learn More 1909
Learn More 1910
Learn More 1911
Learn More 1912
Learn More 1913
Learn More 1914
Learn More 1915
Learn More 1916
Learn More 1917
Learn More 1918
Learn More 1919
Learn More 1920
Learn More 1921
Learn More 1922
Learn More 1923
Learn More 1924
Learn More 1925
Learn More 1926
Learn More 1927
Learn More 1928
Learn More 1929
Learn More 1930
Learn More 1931
Learn More 1932
Learn More 1933
Learn More 1934
Learn More 1935
Learn More 1936
Learn More 1937
Learn More 1938
Learn More 1939
Learn More 1940
Learn More 1941
Learn More 1942
Learn More 1943
Learn More 1944
Learn More 1945
Learn More 1946
Learn More 1947
Learn More 1948
Learn More 1949
Learn More 1950
Learn More 1951
Learn More 1952
Learn More 1953
Learn More 1954
Learn More 1955
Learn More 1956
Learn More 1957
Learn More 1958
Learn More 1959
Learn More 1960
Learn More 1961
Learn More 1962
Learn More 1963
Learn More 1964
Learn More 1965
Learn More 1966
Learn More 1967
Learn More 1968
Learn More 1969
Learn More 1970
Learn More 1971
Learn More 1972
Learn More 1973
Learn More 1974
Learn More 1975
Learn More 1976
Learn More 1977
Learn More 1978
Learn More 1979
Learn More 1980
Learn More 1981
Learn More 1982
Learn More 1983
Learn More 1984
Learn More 1985
Learn More 1986
Learn More 1987
Learn More 1988
Learn More 1989
Learn More 1990
Learn More 1991
Learn More 1992
Learn More 1993
Learn More 1994
Learn More 1995
Learn More 1996
Learn More 1997
Learn More 1998
Learn More 1999
Learn More 2000