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! While you're at it, check out some resources Treehouse students have shared here.

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

General Discussion

Richard Skinner
Richard Skinner
5,839 Points

Is the only option for building a basic site is to copy/paste the html from index and style accordingly?

I was thinking today, would there be any benefits to say, writing up html in blocks using JavaScript (such as the document.write method) and applying them accordingly based on what's needed? I'd figure if you have a 30 page site, it might get cumbersome to have 30 full pages of HTML (lots to tweak and change if necessary), when you might be able to simply have a script in each page that applies the proper structure?

I figure that would be more... Idk, DRY.

But I don't know for sure, and that's why I'm asking :)

Thanks!

1 Answer

Hi Richard Skinner .

Well if you look at it this way HTML is the document that gets painted in the browser. JS is there to add interaction to the HTML.

And when you call a URL you get HTML returned not JS.

An article you might be interested in: https://blog.dareboost.com/en/2016/09/avoid-using-document-write-scripts-injection/

Using document.write you have to rewrite the document DOM. Meaning - performance kill... And if there's an error in JS than page breaks.

And a tip -> you can use a Template Tool like Handlebars or Pug .

That should help.