靜態頁面存取速度優於動態頁面。生成靜態頁後,常需包含外部動態內容 (如最新公告、登入狀態)。本文比較四種主流技術:IFrame、Scriptlets (HTC)、JavaScript document.write、Server-Side Includes (SSI)。
<iframe name="dynamicPart" src="latestNews.htm" width="100%" height="200"
frameborder="0" scrolling="no" allowtransparency="true"></iframe>
allowtransparency<object style="border:0" type="text/x-scriptlet" data="dynamicPart.htm" width="100%" height="200"></object>
<!-- 靜態頁面包含位置 -->
<script src="dynamicPart.js"></script>
<!-- dynamicPart.js 內容 -->
document.write('<div class="news">');
document.write(' <h3>最新公告</h3>');
document.write(' <ul><li>項目一</li><li>項目二</li></ul>');
document.write('</div>');
<!-- #include virtual="/includes/latestNews.asp" --> <!-- IIS/Apache 支援 -->
<!-- #include file="includes/latestNews.asp" --> <!-- 相對路徑 -->
<system.webServer>
<staticContent>
<mimeMap fileExtension=".shtml" mimeType="text/html" />
</staticContent>
<handlers>
<add name="SSI-html" path="*.shtml" verb="*"
modules="ServerSideIncludeModule" resourceType="File" />
</handlers>
</system.webServer>
| 技術 | SEO | 維護性 | 效能 | 瀏覽器相容 | 推薦度 |
|---|---|---|---|---|---|
| IFrame | 差 | 中 | 好 (可獨立快取) | 全 | ★★☆ |
| Scriptlets | 差 | 差 | 中 | 僅 IE | ☆☆☆ |
| JS document.write | 極差 | 差 | 中 (阻塞渲染) | 全 | ☆☆☆ |
| SSI | 優 | 優 | 優 (伺服器端組合) | 全 | ★★★★★ |
| ASP.NET UserControl / Partial View | 優 | 優 | 優 | 全 | ★★★★★ |
| Edge Side Includes (ESI) / Varnish | 優 | 優 | 極優 (邊緣快取組合) | 全 | ★★★★☆ |
@Html.Partial、@await Html.RenderPartialAsync、WebForms UserControlfetch() + innerHTML 替代 document.write,並提供 `