Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript React Basics First Steps in React Render an Element

Kieran Barker
Kieran Barker
15,004 Points

Doesn't this violate the principle of unobtrusive JavaScript?

Previous JavaScript courses taught me that any JavaScript I write should be unobtrusive, meaning that critical parts of the page should not rely on it. Otherwise, on a slow network connection, or with JavaScript disabled, these parts of the page would never be seen.

If we're using React to inject key markup into the page... Doesn't it go directly against the principle of UNOBTRUSIVE JavaScript?

2 Answers

Brendan Whiting
.a{fill-rule:evenodd;}techdegree seal-36
Brendan Whiting
Front End Web Development Techdegree Graduate 84,698 Points

Server side rendering is a way to get around this problem, so at least the first page load is not dependent on JavaScript. But you still might need JavaScript to support other interactions after the page loads.

Unobtrusive JavaScript isn't always possible or necessary. If you know that your users could be using an older browser, or using something like the opera mini browser, you should take this into consideration. The market share of devices without JavaScript is shrinking as browsers get upgraded and hardware devices and infrastructure improve in the developing world. And in a lot of cases, you know who your users are and what browsers they're likely to use. Also, a lot of interactive experiences you really can't do without JavaScript. So the best thing you could do with no JavaScript would be some fallback page that says "sorry, you can't use this feature".

It really does depend on your particular app or site, but it's a heavily opinionated matter. Brendan's response makes it seem like you always need javascript nowadays. However many people don't agree with that and believe that unobtrusive and progressive js is still totally relevant and preferable.