Optimized SVG for Creative Commons CC BY-NC

Optimized SVG for CC BY-NC Attribution-NonCommercial License Logo (includes base64 option)

Using Optimized SVG for Creative Commons Attribution-NonCommercial (CC BY-NC) logo button

By David Hoicka

See GitHub Page: https://github.com/david-hoicka/creative-commons-cc-by-nc-svg-optimized/

This article discusses how to improve Pagespeed website loading for Creative Commons Attribution-NonCommercial (CC BY-NC) 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 Attribution-NonCommercial (CC BY-NC).

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 CC BY-NC SVG image included here is optimized at about 1.5 kb, smaller size for faster HTML page loading than some commonly used Creative Commons CC BY-NC 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 URI's for SVG images
  5. Summary: Lightweight Optimized SVGs for Creative Commons CC BY-NC
  6. Downloads: Optimized SVGs and Base64 Data-URIs for Creative Commons CC BY-NC

Example 1. HTML5 Inline SVG Image Element

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

Creative Commons CC Attribution-NonCommercial (CC BY-NC) License Logo Attribution: http://CreativeCommons.org, Author Creator for this logo button: David Hoicka http://github.com/david-hoicka cc $ BY NC

Example 2. Include SVG using <img> tag

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

Creative Commons CC BY-NC logo

Example 3. Using SVG as a CSS Background-Image

In this third example, the SVG logo for Creative Commons CC BY-NC 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 URI's for SVG images

In this fourth example, the SVG logo for Creative Commons CC BY-NC is inserted as a background-image using a base64 data-URI in CSS. One would think that an unencoded SVG text would work as a data-URI; however, browser support for unencoded SVG text 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: Lightweight Optimized SVGs for Creative Commons CC BY-NC Attribution-NonCommercial

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