久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

管理靜態 HTML 網站中重復代碼的最佳方法是什么

What is the best way to manage duplicate code in static HTML websites(管理靜態 HTML 網站中重復代碼的最佳方法是什么)
本文介紹了管理靜態 HTML 網站中重復代碼的最佳方法是什么的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在管理一個包含大量靜態 HTML 網站的舊網站,沒有服務器端腳本,只有純 HTML/CSS,最少的 javascript.我發現在不同頁面中多次更改同一段代碼非常浪費時間.例如,當菜單中的某些內容發生更改時,由于菜單只是每個文檔中的靜態文本,因此我必須多次進行相同的更改.

I am managing a legacy website with a lot of static HTML websites, no server side scripting, just plain HTML/CSS, minimal javascript. I found it a huge waste of time to change the same piece of code numerous times in different pages. For example, when something in the menu changes, since the menu is just static text in each document, I have to make the same change numerous times.

我想知道將這種開銷降到最低的最佳策略是什么,換句話說,對于跨多個靜態 HTML 頁面管理諸如導航代碼之類的事情,您會推薦什么.

I was wondering what the best tactic would be to minimize this overhead, in other words what would you recommend for managing things like navigation code across multiple static HTML pages.

我知道你可以使用:

  1. 服務器端腳本(如 PHP),但沒有其他理由在該特定站點使用腳本.
  2. 框架(但這很糟糕,因為它......好吧,框架:))
  3. 服務器端包含(似乎在更改服務器時可能會導致麻煩)
  4. javascript(不利于 SEO)

你會推薦什么?

謝謝.

推薦答案

在所有可能性中,無論是您列出的內容還是我所知道的任何其他內容,我仍然會使用基于 PHP 的簡單解決方案來運行.它既簡單又干凈,幾乎不需要您付出任何努力.我對我設計的所有小型網站都這樣做.

Out of all the possibilities, both what you listed and anything else I know of, I'd still just run with a simple PHP-based solution. It's easy and clean, requiring next to no effort on your part. I do this with all the small sites I design.

大多數情況下,您會得到相當簡單的結構.您寫了一整頁,然后對于每個后續頁面,您只需更改內容所在的中間部分.在這種情況下,只需將內容上方和下方的所有內容保存在 header.php 和 footer.php 文件中,然后放入 在每個內容文件的頂部(與頁腳文件類似).完成!

Most often, you end up with fairly trivial structure. You write up a full page, then for each subsequent page you're just changing the bit in the middle where the content lives. In that case, just take everything above and below the content and save it in header.php and footer.php files, then put <?php require_once "header.php"; ?> at the top of each content file (and similarly with the footer file). Done!

這確實有一些小缺點.一方面,您依賴于腳本,但 PHP 是世界上部署最廣泛的服務器端語言,所以這不是一個真正的問題.你甚至不在乎它是 PHP4 還是 PHP5,因為你沒有做任何花哨的事情.

This does have some minor disadvantages. For one, you're depending on scripting, but PHP is the most widely deployed server-side language in the world, so that's not really an issue. You don't even care if it's PHP4 or PHP5, since you're not doing anything fancy.

對于兩個,您在每次頁面加載時都運行一個腳本,以便提供本質上是靜態文件的內容.這會減慢您的響應速度,并對 CPU 造成不必要的壓力.這可能無關緊要(滯后非常小),但如果您發現它很浪費,那么有一些很好的 PHP 框架可以為您提取 PHP 生成的頁面并從中生成靜態 html.(這也很容易自己做,只需使用輸出緩沖做一些工作.)這樣你就可以兩全其美 - PHP 模板(如果你最終想要更花哨的東西,還可以使用完整的 PHP 語言) 但靜態 html 頁面可實現最少的 CPU 活動和最快的頁面加載時間.

For two, you're running a script on every page load, in order to serve what is essentially a static file. That slows down your responses, and stresses the CPU unnecessarily. This probably doesn't matter much (the lag is very minor), but if you find it wasteful, there are some good PHP frameworks which will take your PHP-generated pages and generate static htmls out of them for you. (This is easy enough to do yourself, too, with just a bit of work using output buffering.) This way you get the best of both worlds - PHP templates (and the full PHP language if you end up wanting something fancier down the line) but static html pages for minimal CPU activity and fastest page load times.

這篇關于管理靜態 HTML 網站中重復代碼的最佳方法是什么的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to check for duplicate CSS rules?(如何檢查重復的 CSS 規則?)
Remove duplicate CSS declarations across multiple files(刪除多個文件中的重復 CSS 聲明)
How can I duplicate a div onclick event?(如何復制 div onclick 事件?)
opening html from google drive(從谷歌驅動器打開 html)
How to embed videos from Google drive to webpage?(如何將視頻從 Google 驅動器嵌入到網頁?)
How to view Google drive pdf link in iframe(如何在 iframe 中查看 Google Drive pdf 鏈接)
主站蜘蛛池模板: 亚洲国产精品一区在线观看 | 成人免费视频一区 | 亚洲午夜av久久乱码 | 欧美电影大全 | 亚洲视频www| 国产精品视频一区二区三区不卡 | 亚洲精品乱码久久久久久黑人 | 在线看国产| 国产伦精品一区二区 | 国产一区不卡在线观看 | 卡通动漫第一页 | 久久精品国产99国产精品 | 婷婷福利 | 成人黄在线观看 | 亚洲区一 | 五月激情婷婷六月 | 欧美一级www片免费观看 | 99精品99久久久久久宅男 | 精品视频一区二区三区在线观看 | 国产亚洲一区二区精品 | 黄色一级大片在线免费看产 | 国产精品国产成人国产三级 | 91国内精精品久久久久久婷婷 | 日本手机在线 | 亚洲欧美激情网 | 欧美国产视频一区二区 | 日韩精品一区二区三区四区视频 | 国产高清视频 | 欧美不卡在线 | 在线一区视频 | 久草热播 | 亚洲国产视频一区二区 | 日本中出视频 | 男人av在线播放 | 久草网址 | 中国一级毛片免费 | 久久精品亚洲精品国产欧美 | 久久亚洲一区二区 | 亚洲精品中文字幕 | 欧美男男videos | 青青久久av北条麻妃海外网 |