05.09.10 - Embed images, css and javascript in HTML

Using the "data" URI in the source path of images, css and javascript we can embed it into HTML code

The format of the source path of CSS, javascript and images may not be external. Using the "data" source type we can embed the element into the HTML document. An example of it:
<img alt="Embeded image" src="data:image/png;base64,iVBORw0KGg<div>oAAAANSUhEUgAAADIA..." />
Or CSS:
div.image {
  width:100px;
  height:100px;
  background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIA...);
}
The complication of this method is to get the "base64" encoded content of the object. A simply way to get it is using PHP:
<img alt="Embeded image" src="data:image/jpeg;base64,<?php echo base64_encode(file_get_contents('image.jpg'))?>"/>
Also you can use one of the many online tools for this target.

When you create a HTML document, the structure will not disappear, but what will happen with the external objects?

This is an easy method to secure the content of the objects into the document forever.
More news about:  html
Tags:  php,  streams,  css,  javascript,  base64,  embed

Comments

There are no comments jet. Be the first to comment!

Comment