View on GitHub

Using lightweight optimized SVG images for Creative Commons Plus logo button

Optimized SVG logo button for Creative Commons Plus CCPlus CC+ (includes base64 option)

Download this project as a .zip file Download this project as a tar.gz file

By David Hoicka

See GitHub Page: https://github.com/david-hoicka/creative-commons-plus-svg-lightweight

This article discusses how to improve Pagespeed website loading for Creative Commons Plus (CCPlus, CC+) by using optimized SVGs and Base64 Data-URIs.

Accessibility is also improved using ARIA attributes and tags.

This article outlines 4 ways to optimize SVG image logos for Creative Commons Plus (CCPlus, CC+).

Why use SVG? SVG images often use smaller files. SVGs scale readily as vector images. SVGs can be programmatically controlled and modified.

The Creative Commons Plus SVG included here is optimized at about 1.1 kb, smaller size for faster HTML page loading than some commonly used Creative Commons Plus images.

In addition, although Base64 is generally slightly larger than the original SVG, using Base64 CSS Data-URIs can eliminate one or more HTML requests, as the image data can be cached in the CSS, thus speeding page load and Pagespeed.

Kindly refer to page source view for code details.

  1. Example 1. HTML5 Inline SVG Image Element
  2. Example 2. Include SVG using <img> tag
  3. Example 3. Using SVG as a CSS Background-Image
  4. Example 4. Using Base64 Data URIs for SVG images
  5. Summary: Use Lightweight Optimized SVGs and Base64 Data-URIs for Creative Commons Plus
  6. Downloads: Optimized SVGs and Base64 Data-URIs for Creative Commons Plus

Example 1. HTML5 Inline SVG Image Element

In this first example, the SVG logo for Creative Commons Plus is placed inline as an HTML5 <SVG> element:

Creative Commons Plus CCPlus CC+ Commercial License Logo Attribution: https://wiki.creativecommons.org/wiki/CCPlus, Author Creator for this logo button: David Hoicka http://github.com/david-hoicka + COMPANY COMMERCIAL LICENSE

Example 2. Include SVG using <img> tag

In this second example, the SVG logo for Creative Commons Plus is inserted from a separate SVG file using an HTML5 <IMG> element:

Creative Commons Plus CCPlus CC+ logo

Example 3. Using SVG as a CSS Background-Image

In this third example, the SVG logo for Creative Commons Plus is inserted as a background-image using CSS:

The SVG image size can be set using CSS. For example, this image size is set to 90px x 30px using CSS:

Next, the image size can be changed by setting CSS width and height to 14em x 5em, and the enlarged SVG image generally remains crisply rendered:



Example 4. Using Base64 Data URIs for SVG images

In this fourth example, the SVG logo for Creative Commons Plus is inserted as a background-image using a base64 data-URI in CSS. One would think that an unencoded SVG would work as a data-URI; however, browser support for unencoded SVG data-URIs is variable.

As a further point of interest, this Example 4 creates a clickable background-image link:

Similarly, the SVG image size can be changed by setting CSS width and height to 14em x 5em, and the enlarged SVG image generally shows as crisply rendered:



Summary: Use Lightweight Optimized SVGs and Base64 Data-URIs for Creative Commons Plus

As shown above, there are several common options for SVGs in HTML5 webpages, each with pros and cons.

Here are the download links:

David Hoicka