大网数据广告活动
网站运营与故障问答

Loading an external HTML file into another - does it have an affect on SEO?

· 52CE 我爱测

I have my first web project which will approximately be 50 pages. Up until now I've just done 5 page websites, so if I needed to e.g. add a navigation link, I would just quickly type the code and copy and paste it into all 5 HTML…

问题原文

原帖链接 · SteveyG · CC BY-SA 3.0

I have my first web project which will approximately be 50 pages. Up until now I've just done 5 page websites, so if I needed to e.g. add a navigation link, I would just quickly type the code and copy and paste it into all 5 HTML files..

I'm looking for the 'best practice' sort of way so I can update the navigation links somewhere, and it'll update every page..

I saw this solution on StackOverflow:

Homepage Code:

<div id="nav-container">

</div>

<script>
$(function(){
$("#nav-container").load("navigation-links.html");
});

navigation-links.html file:

<div class="nav-btn1">Link</div>
<div class="nav-btn2">Link</div>
<div class="nav-btn3">Link</div>
<div class="nav-btn4">Link</div>

But as the html links aren't within the actual pages, would this have a negative impact from an SEO standpoint?

If so, is there another way I should be doing this?

已采纳解答

原帖链接 · WebElaine · CC BY-SA 3.0

JS includes can be problematic for several reasons - search engines don't always process them properly, they are often not accessible to visitors using alternative technologies like screen readers, and like you said - this particular version isn't even outputting actual links.

One option is to move to a CMS, which would allow you to manage all the sitewide components in one place and have them update on every page.

A simpler option that would let you keep your static HTML files would be to use Server Side Includes (SSI). You'll have to check with your host to see whether they are allowed; some hosts disable them for security reasons, but they're not a big risk as long as you are only including your own files.

You would create one file to hold the sitewide navigation, something like nav.html:

<a href="/">Home</a>
<a href="/page1.html">Page 1</a>
<a href="/page2.html">Page 2</a>

etc., and then in every static file, where you want the navigation to appear, you would include that file:

<!--#include file="nav.html"-->

You can do the same with footer, sidebar, etc. so you only have to make updates in a single file and they are then pulled into all your other files.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2018-04-27)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。