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

管理靜態(tài) HTML 網(wǎng)站中重復(fù)代碼的最佳方法是什么

What is the best way to manage duplicate code in static HTML websites(管理靜態(tài) HTML 網(wǎng)站中重復(fù)代碼的最佳方法是什么)
本文介紹了管理靜態(tài) HTML 網(wǎng)站中重復(fù)代碼的最佳方法是什么的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

我正在管理一個(gè)包含大量靜態(tài) HTML 網(wǎng)站的舊網(wǎng)站,沒有服務(wù)器端腳本,只有純 HTML/CSS,最少的 javascript.我發(fā)現(xiàn)在不同頁(yè)面中多次更改同一段代碼非常浪費(fèi)時(shí)間.例如,當(dāng)菜單中的某些內(nèi)容發(fā)生更改時(shí),由于菜單只是每個(gè)文檔中的靜態(tài)文本,因此我必須多次進(jìn)行相同的更改.

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.

我想知道將這種開銷降到最低的最佳策略是什么,換句話說(shuō),對(duì)于跨多個(gè)靜態(tài) HTML 頁(yè)面管理諸如導(dǎo)航代碼之類的事情,您會(huì)推薦什么.

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. 服務(wù)器端腳本(如 PHP),但沒有其他理由在該特定站點(diǎn)使用腳本.
  2. 框架(但這很糟糕,因?yàn)樗?.....好吧,框架:))
  3. 服務(wù)器端包含(似乎在更改服務(wù)器時(shí)可能會(huì)導(dǎo)致麻煩)
  4. javascript(不利于 SEO)

你會(huì)推薦什么?

謝謝.

推薦答案

在所有可能性中,無(wú)論是您列出的內(nèi)容還是我所知道的任何其他內(nèi)容,我仍然會(huì)使用基于 PHP 的簡(jiǎn)單解決方案來(lái)運(yùn)行.它既簡(jiǎn)單又干凈,幾乎不需要您付出任何努力.我對(duì)我設(shè)計(jì)的所有小型網(wǎng)站都這樣做.

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.

大多數(shù)情況下,您會(huì)得到相當(dāng)簡(jiǎn)單的結(jié)構(gòu).您寫了一整頁(yè),然后對(duì)于每個(gè)后續(xù)頁(yè)面,您只需更改內(nèi)容所在的中間部分.在這種情況下,只需將內(nèi)容上方和下方的所有內(nèi)容保存在 header.php 和 footer.php 文件中,然后放入 在每個(gè)內(nèi)容文件的頂部(與頁(yè)腳文件類似).完成!

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!

這確實(shí)有一些小缺點(diǎn).一方面,您依賴于腳本,但 PHP 是世界上部署最廣泛的服務(wù)器端語(yǔ)言,所以這不是一個(gè)真正的問(wèn)題.你甚至不在乎它是 PHP4 還是 PHP5,因?yàn)槟銢]有做任何花哨的事情.

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.

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

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.

這篇關(guān)于管理靜態(tài) HTML 網(wǎng)站中重復(fù)代碼的最佳方法是什么的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

How to check for duplicate CSS rules?(如何檢查重復(fù)的 CSS 規(guī)則?)
Remove duplicate CSS declarations across multiple files(刪除多個(gè)文件中的重復(fù) CSS 聲明)
How can I duplicate a div onclick event?(如何復(fù)制 div onclick 事件?)
opening html from google drive(從谷歌驅(qū)動(dòng)器打開 html)
How to embed videos from Google drive to webpage?(如何將視頻從 Google 驅(qū)動(dòng)器嵌入到網(wǎng)頁(yè)?)
How to view Google drive pdf link in iframe(如何在 iframe 中查看 Google Drive pdf 鏈接)
主站蜘蛛池模板: 欧美一级黄色免费看 | 欧美色性 | 欧美日韩一区二区在线观看 | 超碰在线人人 | 国产 欧美 日韩 一区 | 国产99久久精品一区二区300 | 三级在线免费观看 | 色约约视频| 黄色网址在线播放 | 久久久久国产精品 | 欧美精品在欧美一区二区少妇 | 男人天堂国产 | 99成人 | 三级黄色片在线观看 | 午夜精品 | 国产在线不卡视频 | 日本不卡一区二区三区在线观看 | 嫩草一区二区三区 | 91精品国产91久久久久久最新 | 青青久在线视频 | 欧美精品欧美精品系列 | 一区二区三区在线免费观看 | 日本精品久久 | 日韩在线不卡 | 四虎影音 | 在线观看av网站永久 | 一区二区三区国产 | 亚洲精品国产成人 | 亚洲不卡 | www.色午夜.com | 国产成人一区二区三区电影 | 国产99久久精品一区二区永久免费 | 国产一区免费 | 草草影院ccyy| 亚州精品天堂中文字幕 | 国产乱码久久久 | 在线中文字幕视频 | 欧美亚洲在线 | 青青草精品 | 91偷拍精品一区二区三区 | 日日夜夜天天久久 |