Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Liam Maclachlan
Liam Maclachlan
22,805 Points

SOLVED: Javascript or <noscript>?

I guess this is a question of functionality vs resources available....

I am trying to add fail-safes for lazy-loading when JS is not an option.

Will it take more resources, in relation to the likelyhood of the 'noscript' tag failing, to dynamically add the content with Javascript?

I imagine using Javascript to add content when Javascript is availble is the best option... but will this be too user-resource heavy? (I would use Javascript to stop the loading of the fail-safe content where needed)

Just a heads up, I am creating a fall back for lazyloaded images :)

to reiterate:

  • Does it make more sense to use Javascript to poulate content reliant on Javascript and avoid using 'noscript' tag (due to its sporadic nature of working) to make sure that the correct content is displayed in both scenarios, in relation to the likelyhood of failing vs clientside resources?

Your suggestions, please :)

1 Answer

Liam Maclachlan
Liam Maclachlan
22,805 Points

I have just flipped it around. I am using JS to remove content that is not reliant on JS.

The lazy loaded images will not render due to the src attribute not being 'correct' if JS is not available, due to the nature of lazy-loading.

This is my current code where jQuery is removing the content with the class 'no-script' when JS is present:

<img class="lazy" data-original="http://lorempixel.com/g/1080/278/abstract">
<img class="no-script" src="http://lorempixel.com/g/1080/278/abstract">

Seeing that the first one will not render if JS is not present anyway, this should work(?)

I'm starting to think, more and more, that this is probably the best fall back for lazy loading