Specifying content of an iframe instead of the src attribute to a page
Fast and furious: inline iframe
content without src
by leveraging srcdoc
attribute:
Monolith coding: Keep your HTML and iframe
content in a single document, and say goodbye to external page-load stress with srcdoc
. When srcdoc
can't cover it, write JavaScript directly into an iframe
initialized with src="about:blank"
.
Write into iframes using JavaScript
Scripting dynamic content
Kick off with an iframe
filled with nothing but sweet, sweet white space:
Bring this blank canvas to life with a dash of JavaScript:
Conquering advanced techniques
Create a clean slate with about:blank
or manage content dynamically with JavaScript. Use data:
URLs to load stuff into your iframes:
Enjoy the power of encodeURIComponent
and data:
URLs to stuff the iframe
like a Thanksgiving turkey.
Template-storing and Optimizations
Script a plan by sandwiching your HTML template between <script type="text/template">
tags:
Slide this HTML goodness into your iframe
when the time is right:
Avoid Mayhem of nested iframes: steer clear of slow loads and headaches.
Painting the big picture
When should I use srcdoc vs. data URLs?
The choice is simple: srcdoc
when you've your content in a string, ready to rock 'n roll. Choose data URLs when you're dealing with dynamic content, or when you need encodeURIComponent
to handle the rowdy, special characters.
Boosting performance in paint by numbers
Enhanced performance is all about smart content management. Try HTML-tag hide and seek: nestle your HTML content templates in the humble <script>
tag camouflage, effectively dodging loading bottlenecks.
Handling intricate designs
With art, intricacy equals complexity. Keep the loading delays at bay caused by DOM chaos. The classic doc
penmanship works well for most, but intricate designs cry out for a more refined quill: the data URLs.
Was this article helpful?