Rich media developer's guide

Reduce HTML5 file size

An HTML5 creative commonly refers to ads created with HTML, CSS, and JavaScript. HTML5 creatives provide many opportunities to compress your files. Many of the tips provided below can be implemented in under 15 minutes.

Use Google Web Designer

Google Web Designer is a web application for HTML5 development that's integrated seamlessly with Studio and Asset Library. In addition, Google Web Designer has built-in compression for images and code, Google web fonts support, SVG support, CSS animation support, and more.

Get started with Google Web Designer

Check your file size

Before reducing file size, check out your current file size and review the following guidelines and terms.

Raw file size vs. compressed file size

To review your raw file size:

  • In Studio, check your Total file size in the Manage files step of the Studio creative workflow.
  • In Google Web Designer, click Publish > Publish locally to view Total Size (Raw) in the publish dialog. You can also view the current file size in the Ad Validator panel.

Google Web Designer compresses creatives with the free software gzip. If you're not using Google Web Designer, you can download a free copy of gzip, compress them on your local workspace, and inspect the file size.

The publisher’s ad server may use a different means of compression, so it's a good idea to check with your publisher to resolve potential disagreements over compressed size calculations.

File size baseline

Before you build your creative, it’s essential to understand your publisher’s ad serving specifications. However, many publishers follow the IAB recommendation of 200 KB (compressed) initial load for the creative and 300 or 500KB for the total creative size (depending on format). Initial load refers to the total, compressed file size of all creative assets delivered to the browser for initial ad display. This includes all files—images, HTML, CSS, and JavaScript.

Enabler file size

The Enabler must be included in Studio creatives, but web browsers hold a cached copy, because the same script is loaded for every Studio creative. The size of the Enabler script is 25 KB (compressed) and 75 KB (raw).

See the IAB and Studio guidelines for additional details:

About Chrome's Heavy Ad Interventions

Creatives with a file size larger than 4 MB, CPU usage of more than 15 seconds per 30-second period, or 60 seconds of total CPU usage might be unloaded by Chrome at serving time.

Polite load and publisher specs

Polite loading delays the loading of additional creative assets (like images and video) until the publisher's page is loaded. This is different than initial load, which refers to the total, compressed file size of all creative assets delivered to the browser for initial ad display. Some publishers require polite loading, but it's a good idea to include it, even when it's not required. Learn how to set up polite load

Review your publisher's Rich Media HTML5 specs. Publishers may count file size based on the compressed gzip format, or they may prefer to count the raw file size. Individual publisher specs may differ from IAB specs depending on placement, ad type, etc. Some publishers may be more willing to compromise on build specs. Also take note of any limits for animation or video play time.

Reduce image size

Before you attempt to reduce the size of an image, first consider whether an image is even necessary. Some image elements may be replaced with CSS styles. Below are suggestions and resources for reducing the number of images in your creative and for optimizing the images you need.

Use CSS to create gradients or solid colors
CSS renders color and gradients much more efficiently than an image. For help with creating CSS gradients, use CSSmatic's Gradient Generator.
Replace GIF, JPG, and PNG with SVG (Scalable Vector Graphics)

GIF, JPG, and PNG images are pixel based (“raster”) and have larger sizes. SVGs are point-to-point based graphics (“vector”) and can greatly reduce file size.

Learn more about SVG
W3School's SVG Tutorial
How to Use SVGs
Compressing SVGs

If you're using lots of icons, consider using an icon font instead

Icon fonts are regular fonts that can be used just like standard fonts. They're often vector based, which reduces file size. If you use the same icons over and over, build your own icon font.

Icon font resources
Icomoon Icon Font Creator
NounProject css icons
FontAwesome css icons

Use a sprite sheet to optimize load time for pixel based images

A sprite sheet is a single tiled image that is loaded once. With CSS, only individual tiles of the overall image are shown. Using a sprite sheet reduces the number of HTTP requests. The fewer HTTP requests, the faster your creative loads. It's still important to find the right compression for your sprite sheet.

Sprite sheet resources
W3School's CSS Image Sprites Overview
Stitches online sprite sheet generator

Use the best compression

If pixel based images are required, compress them as much as possible while preserving quality. You're probably familiar Photoshop’s Save For Web, but there are other online tools that offer advanced compression.

Free Image compressors
TinyPNG
TinyJPG

Animate with CSS

Consider using CSS3 animations for transitions and transforms instead of JavaScript. CSS transforms use the GPU (Graphics Processing Unit) instead of the CPU (Central Processing Unit) for rendering animations, which improves performance and reduces JavaScript file size.

For more complex animations (including particle animations), consider using GreenSock’s JavaScript animation libraries (GSAP). GreenSock simplifies the more cumbersome aspects of CSS animation, such as adjusting the timing of multiple animations and independently animating transform properties.

Don't use JavaScript libraries or frameworks that use JavaScript's setInterval method for animations, and do not use the setInterval method when hand coding. setInterval uses up a lot of browser resources, affects performance, and requires more code. If JavaScript animations are mandatory, then consider using the requestAnimationFrame method, which is specifically made for animations.

Learn how to optimize animation performance
Using requestAnimationFrame
CSS vs JavaScript Animations

Before uploading your CSS files to Studio, minify your CSS with a CSS Minifier.

Reduce JavaScript file size

Here are some tips for reducing your JavaScript file size:

Don’t use jQuery
jQuery adds unnecessary file size (~75k) even though the majority of the jQuery library is not used. Instead, convert from jQuery to pure JavaScript, use a minimalist library like Zepto.js, or consider GreenSock's TweenLite.
Avoid using JavaScript frameworks
Consider taking useful pieces out of a JavaScript framework for use in your main Javascript file to reduce both file size and network requests.
Use Studio's hosted JavaScript libraries

Instead of uploading JavaScript libraries with your creative, replace any references to common JavaScript libraries with Studio hosted URLs. These libraries are hosted on the same domain as your live ad will be.

Studio is working with the IAB to get these resources shared and cached by many creatives so they can be excluded from the initial load of your ad.

Target specific browsers and devices

Save time and code by deciding what browsers and devices your campaign will target. Don't add code for unsupported browsers or devices. This will also save you time during testing.

Browser support resources
Browser and device support for Studio
Can I Use: Up to date browser support for JS and CSS properties

Combine and compress your JavaScript
If you have multiple JavaScript files, combine them into one. Use tools that remove comments and extra whitespace from your JavaScript.

Tips for minifying
  • Keep an uncompressed copy handy for future updates.
  • Studio requires that JavaScript files have a .js extension, not .min.js.
  • If you minify your JavaScript files, you can't easily add tracking. Add tracking first, then minify the JavaScript file.

Optimize fonts

If you're using a font other than the standard web fonts, consider using Google Fonts, a large library of free fonts. To reduce file size, be sure to only request the characters you need from the font instead of the entire typeface.

However, it's also important to consider that only absolute URLs are cached by a browser. Although http://fonts.googleapis.com/css?family=Philosopher&text=Hello will be the smallest size for a specific creative, it will still be seen as a separate request from http://fonts.googleapis.com/css?family=Philosopher&subset=latin, which may already be cached in the browser history. Take advantage of caching whenever possible to make your creatives load faster.

Learn more about web fonts
Optimizing font requests with Google Web Fonts
Font subsetting for Typekit and self-hosted web fonts

Was this helpful?

How can we improve it?

Need more help?

Try these next steps:

Search
Clear search
Close search
Google apps
Main menu
13139301287953210274
true
Search Help Center
true
true
true
true
true
74220
false
false