代码示例:
无页面导航:
<body>
<nav>
// Navigation links to the parts of the site.
// Clicking a link calls a javascript function to display the relevant <div>
</nav>
<section id="page1">
// Page 1 content
</section>
<section id="page2">
// Page 2 content
</section>
</body>
页面导航:
// Page1.php:
<body>
<nav>
// Navigation links to parts of the site.
// Act as normal <a> tags, redirecting the browser to the new page
</nav>
<section>
// Page1 content
</section>
</body>
// Page2.php:
<body>
<nav>
// Navigation links to parts of the site.
// Act as normal <a> tags, redirecting the browser to the new page
</nav>
<section>
// Page2 content
</section>
</body>
链接导航的优点:
浏览器不需要一次加载整个网站
无需 javascript 即可使用该网站
提供直接 URL 以便于导航
似乎是标准的做法
javascript 导航的优点:
对于具有大量服务器端脚本的站点(例如我的),最大限度地减少页面请求
不需要在不同的地方使用相同的代码(
<nav>
例如元素)。在 PHP 中创建一个echo_nav_html()
函数并不是一个好的解决方案,因为它使在 IDE 环境中的编码变得烦人初始加载后,站点速度超快,因为几乎没有任何新请求发送到服务器
哦,明智的互联网,对此有什么想法吗?
或者也许更优雅的解决方案提供列出的 javascript 导航的优点?