By Ali Mottaghi Pour


2019-03-13 00:33:31 8 Comments

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.

2 comments

@Chris Rutherfurd 2019-03-13 07:59:10

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.

@Ali Mottaghi Pour 2019-03-13 14:18:52

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.

@zachzurn 2019-03-13 08:01:52

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.

@Ali Mottaghi Pour 2019-03-13 14:00:32

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.

@zachzurn 2019-03-13 16:38:17

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).

Related Questions

Sponsored Content

3 Answered Questions

[SOLVED] Is changing HTML with JavaScript bad for SEO?

  • 2014-03-01 21:32:59
  • Mike
  • 2152 View
  • 4 Score
  • 3 Answer
  • Tags:   seo javascript

1 Answered Questions

[SOLVED] SEO for importing the page header with JavaScript rather than PHP

1 Answered Questions

[SOLVED] Cloudflare: Cache static HTML when URL has Query String

  • 2016-03-10 22:09:02
  • Festus Martingale
  • 2173 View
  • 10 Score
  • 1 Answer
  • Tags:   html cache cloudflare

1 Answered Questions

[SOLVED] Is having multiple index files for various devices bad SEO?

1 Answered Questions

[SOLVED] For a given web page, what is the order of appearance in the HTML code for SEO?

  • 2015-10-05 13:57:08
  • ElHaix
  • 79 View
  • 1 Score
  • 1 Answer
  • Tags:   seo html

3 Answered Questions

[SOLVED] Redirect from 404 page to homepage after some seconds and SEO impact

  • 2015-06-21 09:08:22
  • miduga
  • 1330 View
  • 3 Score
  • 3 Answer
  • Tags:   seo redirects 404

1 Answered Questions

1 Answered Questions

[SOLVED] Preventing Cache for Text Content but not for CSS files and Images

  • 2014-08-14 21:28:11
  • NecNecco
  • 61 View
  • 1 Score
  • 1 Answer
  • Tags:   wordpress cache

1 Answered Questions

Sponsored Content