SHARE
Facebook X Pinterest WhatsApp

Sneaky CSS and JavaScript Tricks Using HTML 5

Sep 8, 2010

There are some sneaky tricks that can be accomplished using CSS, HTML 5’s canvas tag, JavaScript and PNG images. An example would be the hack developed by Jacob Seidelin at Nihilogic.dk, who used PNG images to compress the HTML and JavaScript on a web page by up to 75%.


Seidelin created the hack, which has been used by other participants at the 10K An Event Apart competition, although some may debate the merits of using such a hack in the event.
The idea is to compress the CSS and JavaScript code using a compression tool, encode it as a PNG graphic, extract the code from the image, such as when the image is loaded into a canvas element using the drawImage() method, and converting the data to a string.


By using Seidelin’s method, you could save 75% of the file size, and in some cases, even beat the compression savings of those files compressed using Gzip. That said, it’s usually easier and better to use the Gzip format.

Recommended for you...

Web 3.0 and the Future Of Web Development
Rob Gravelle
Jun 23, 2022
CodeGuru and VBForums Developer Forums and Community
James Payne
Apr 7, 2022
Understanding CSS Template Layout
Vipul Patel
Mar 29, 2022
Criminals Pay More for Code Signing Certificates Than for Guns or Passports
HTML Goodies Logo

The original home of HTML tutorials. HTMLGoodies is a website dedicated to publishing tutorials that cover every aspect of being a web developer. We cover programming and web development tutorials on languages and technologies such as HTML, JavaScript, and CSS. In addition, our articles cover web frameworks like Angular and React.JS, as well as popular Content Management Systems (CMS) that include WordPress, Drupal, and Joomla. Website development platforms like Shopify, Squarespace, and Wix are also featured. Topics related to solid web design and Internet Marketing also find a home on HTMLGoodies, as we discuss UX/UI Design, Search Engine Optimization (SEO), and web dev best practices.

Property of TechnologyAdvice. © 2025 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.