Is it a bad idea to embed unimportant static HTML code in a JavaScript file? Could it harm SEO?

For example, the footer or header HTML code is constant and those sections load for many different pages. If I embed these sections in a JavaScript file, browsers can cache them.

For example, in the JavaScript file I would use $("#mainFooter").html("...") and embed the HTML code for the footer in the string. Then I would link the JavaScript file on the page using a script tag.

  • Why did you roll back the grammar edits that I made? Closing as "unclear" until grammar is improved again. Mar 13, 2019 at 2:23
  • @StephenOstermiller Your edit was false. You change question to ajax and boilerplate!!! My question is clear. Add static part of page by javascript not ajax! Mar 13, 2019 at 2:30
  • for example: $("#mainFooter").html("...") Mar 13, 2019 at 2:33
  • 2
    @AliMottaghiPour Thanks for the clarification. I've edited your question so that it is clear to read, and hopefully preserves your intention. Your question was ambiguous when you first posted it, which is why Stephen interpreted it in a different way than you intended. Hopefully it is what you meant now. I nominated your question for re-opening. Mar 13, 2019 at 3:20
  • 1
    Boilerplate text is static text that appears on all pages of your site. See en.wikipedia.org/wiki/Boilerplate_text Mar 13, 2019 at 10:30

2 Answers 2


Google indexes Javascript. See the article here:

See: https://webmasters.googleblog.com/2014/05/understanding-web-pages-better.html

... we decided to try to understand pages by executing JavaScript.

Take note of this section of the article:

It's always a good idea to have your site degrade gracefully. This will help users enjoy your content even if their browser doesn't have compatible JavaScript implementations. It will also help visitors with JavaScript disabled or off, as well as search engines that can't execute JavaScript yet.

Loading your header and footer via javascript does not allow the website to degrade gracefully.

Additionally, other search engines may not be able to index pages that use javascript.

  • Tanks but I indicate to unimportant sections of pages that if they wouldn't add to page, page can work correctly, for example, in current page, if the browser doesn't load footer, we still can use it correctly. Mar 13, 2019 at 14:00
  • The point of all of this is to give you information regarding your question. The fact that you are wondering if it affects SEO tells me that you have something important in the content (like site navigation).
    – zachzurn
    Mar 13, 2019 at 16:38

With regard to the SEO aspect of your question it is unlikely to affect how Google crawls and indexes your site as Google is able to interpret the way your JavaScript operates and affects the page in order to accurately gauge what your end users will see for more accurate and relevant indexing and ranking.

Now just because Google "can" crawl and index your JavaScript powered pages does not necessarily mean that you should make them JavaScript powered. in the grand scheme of things shifting your header and footer html into JavaScript for caching purposes is not going to dramatically impact on your page load times which is the main purpose of caching content. You are also more likely to make your site for all intents and purposes unusable for end users who choose not to have JavaScript enabled. There are also quite a few users out there who disable caching or run automatic tools on their computers to clear their browser cache fairly regularly (I do mine weekly) for various reasons as part of general computer maintenance. By embedding your html code in the JavaScript not only are you not benefiting from caching in these instances but you are taking even longer now to display the page to the user as the JavaScript file needs to be downloaded to the end user first and then processed before the static HTML can be added to the page.

The only reason I would embed static HTML into a JavaScript file is for ease of maintenance where certain HTML has to be added to multiple websites for branding purposes (such as university or enterprise websites).

So short answer is should not affect your SEO but certainly not recommended practice.

  • Tanks but I indicate to unimportant sections of pages that if they wouldn't add to page, page can work correctly, for example, in current page, if the browser doesn't load footer, we still can use it correctly. I think 99% of normal users, use browsers that they enable JavaScript and if these users clear cache, They have to download JavaScript again but for one time. I think we must only send dynamic content by HTML and other static codes can be cached. Let me know if I missed anything. Mar 13, 2019 at 14:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.