TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask News.YC: Is hand-coded html an outdated and silly way to operate a site?

4 点作者 bmaier超过 17 年前
It seems like everyone these days is using some sort of CMS. Is there any reason to code the pages by hand anymore for a frequently updated site? One of the few upsides I can see is the speedier load time of non-cms sites because of the lack of need for a database interaction but other than that I can't think of much else. <p>Anyone out there not using some sort of CMS for a site of reasonable complexity?

3 条评论

tlrobinson超过 17 年前
For really simple sites that don't need a full blown database backed CMS I just use simple PHP includes like the following:<p><pre><code> &#60;?php $title = "Whatever"; include("header.php"); include("content.txt"); // or just include the content inline include("footer.php"); ?&#62; </code></pre> Then header.php is just:<p><pre><code> &#60;html&#62; &#60;head&#62; &#60;title&#62;My Site - &#60;?php echo $title; ?&#62;&#60;/title&#62; &#60;!-- other header stuff like css, scripts, etc --&#62; &#60;/head&#62; &#60;body&#62; &#60;div id="content"&#62; </code></pre> and footer.php is just:<p><pre><code> &#60;/div&#62; &#60;!-- other footer stuff like Google Analytics, etc --&#62; &#60;/body&#62; &#60;/html&#62; </code></pre> If you want to get a little fancier you can set up a URL rewriting (like Apache's mod_rewrite) to internally change yoursite.com/section/subsection to yoursite.com/content.php?a=section&#38;b=subection or something, then you can eliminate all the duplicate templates and just have your content files (<i>make sure you validate the section and subsection names</i>). Or you could plug in a really simple database.<p>I'm no PHP expert, so if anyone has better ways of doing this kind of thing I'd love to hear it.<p>(actually, I have a question: with this layout it's hard to pass data from included files back up to the templates, like $title above needs to be defined before the header include... is there some trick I'm missing?)
boucher超过 17 年前
"Is there any reason to code the pages by hand anymore for a frequently updated site?"<p>There hasn't been a reason to hand code anything that is at all dynamic or frequently updated for a decade. There's a reason PHP is so popular after all.<p>That being said, any HTML/CSS that has to do with layout is still best done by hand. <p>On the spectrum of tools available, what most people are looking for is a hand-coded layout/template with something like wordpress/moveable type generating the content.
thomasswift超过 17 年前
I used to do a simple rails site for anything I put on the web. I switch to html based site for things that I wasn't updating much. The reason was to save on memory usage on my vps.<p>For a site of any complexity, I would use a cms, home-brewed or open-sourced though. <p>Removing the database layer is always a nice option, but if you plan to have any sort of interactivity, straight html might be a pain.