框架可以用什么代替?

发布于 2024-11-04 03:46:51 字数 455 浏览 4 评论 0原文

假设我有一个包含 50 个网页的网站。每个页面都包含

  1. 标题
  2. 导航
  3. 左侧内容
  4. 右侧内容
  5. 页脚

不使用

  1. 框架
  2. 服务器端编程
  3. 第三方工具和软件
  4. 框架

我需要将这 5 个部分中的每一个的代码(HTML 标记)放入这 50 个页面中的每一个中? “一次编码,一次又一次使用”这个术语怎么了?另外,如果我想改变任何东西,我需要改变 50 个地方。这只是多余的。我可以这样使用吗?

<object type="text/html" height="100%" width="100%" data="header.html"></object>

请原谅我的愚蠢问题。学习硬道理!

Lets say I have a web site with 50 web pages. Each page consists of

  1. A Header
  2. Navigation
  3. Left Side Content
  4. Right Side Content
  5. Footer

Without using

  1. Frames
  2. Server side programming
  3. Third part tools and softwares
  4. Frameworks

I would need to put the code (HTML Markup) for each of these 5 sections in each of those 50 pages? What happened to the term "Code Once, Use Again & Again"? Also If I want to change any thing, I would need to change it at 50 places. This is just reduntant. Can I use as such.

<object type="text/html" height="100%" width="100%" data="header.html"></object>

Excuse my stupid questions. Learning the hardway!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

鸢与 2024-11-11 03:46:51

我需要将这 5 个部分的代码(HTML 标记)分别放入这 50 个页面中吗?

是的

术语“一次编码,再次使用”发生了什么?

您拒绝了所有在 HTML 中实现这一点的技术(好吧,除非您从头开始编写自己的模板引擎(没有第三方工具)并在构建时运行它而不是按需运行(没有服务器端代码),或者使用 JavaScript (这太疯狂了))。

我可以这样使用吗?

这实际上是一个 ,只是功能较少且浏览器支持较弱。

I would need to put the code (HTML Markup) for each of these 5 sections in each of those 50 pages?

Yes

What happened to the term "Code Once, Use Again & Again"?

You rejected all the techniques that make that possible in HTML (well, unless you count writing your own template engine from scratch (no third party tools) and running it at build time instead of on demand (no server side code), or using JavaScript (which is insane)).

Can I use as such. <object type="text/html" height="100%" width="100%" data="header.html"></object>

That is effectively an <iframe>, just with fewer features and weaker browser support.

意犹 2024-11-11 03:46:51

您描述了服务器端语言的确切用例。

让我向您解释一下您的方法存在的问题。如果您以这种方式创建您的网站,并通过 objectiframe 包含 index.html 和其他 5 个部分,这将意味着向您的服务器发送 6 个请求(这当然不是一个好的做法)。

事情会发生这样:

  • 浏览器请求你的 index.html
  • 解析它,发现它还需要请求 header.html 和其他四个
  • 服务器请求所有这 5 个 html

从 ,您可以只请求 index.php 例如(如果您使用 PHP),让 PHP 构造 ONE HTML 资源(可能包括其他 PHP 文件,例如 header.php)。 php)并将其发送到浏览器,这会很高兴地显示它。

您不必打破学习顺序,只需将一些小部分用于此特定目的(根本只使用一个命令)。保持灵活性,你会发现它在这个行业非常有用:)。

举个例子:

index.php

<!DOCTYPE html>
<html>
...
<body>

<?php include 'header.php'; ?>

<?php include 'navigation.php'; ?>

...

<?php include 'footer.php'; ?>

</body>
</html>

在你的 PHP 文件中,你只能有简单的 HTML,只是文件扩展名会有所不同。要编写 PHP 命令,您可以使用

You describe the exact use case for a server-side language.

Let me explain you the problem with your approach. If you do your site this way, having an index.html and those other 5 parts you include through either object or iframe, this will mean 6 requests to your server (which is certainly not a good practice).

Things will happen like this:

  • Browser requests your index.html
  • Parses it and finds it also needs to request header.html and four others
  • Requests all those 5 htmls from the server

Instead, you could just request index.php for example (if you use PHP), let PHP construct ONE HTML resource (possibly including other PHP files, like header.php) and send it to the browser, which will happily display it.

You don't have to break your learning order, only use some small parts for this specific purpose (using only one command at all). Be flexible, you will find it very useful in this business :).

To give you an example:

index.php

<!DOCTYPE html>
<html>
...
<body>

<?php include 'header.php'; ?>

<?php include 'navigation.php'; ?>

...

<?php include 'footer.php'; ?>

</body>
</html>

In your PHP files, you can have only simple HTML, only the file extension will be different. To write PHP commands you can use <?php whatever ?>

心是晴朗的。 2024-11-11 03:46:51

您还可以通过组合不同的部分来实现这一目标,这意味着您将标题写入一个文件,导航到另一个文件,将内容写入第三个文件,然后将它们组合到实际的网页中。 (基本上是制作自己的模板引擎)。例如(在 UNIX 中)

cat header.html navigation.html body1.html > page1.html

不是理想的解决方案,但这样您只需要更改一次。但对于任何真实的事情,已经建议的服务器端脚本通常是最佳选择。

You could also achieve the goal by just combining different parts, meaning that you write your header in one file, navigation to another and content to third file and then combine these to actual webpages. (basically making your own template engine). Such as (in UNIX)

cat header.html navigation.html body1.html > page1.html

Not the ideal solution but this way you only need change once. But for anything real, already suggested server-side scripting is best option usually.

緦唸λ蓇 2024-11-11 03:46:51

如果您不想使用服务器端编程(这是它为您而构建的),您唯一的选择是 AJAX 调用来在运行时填充公共元素。

然而,这不会提供非常好的用户体验,因为页面在似乎完成加载后会慢慢加载。

您确实应该为此使用服务器端编程。

If you don't want to use server side programming (which is what it was built for mind you), your only choice is an AJAX call to fill in the common elements at run time.

This however will not provide a very good user experience, as the page slowly loads itself AFTER it seemed to finish loading.

You really should use server side programming for this.

三五鸿雁 2024-11-11 03:46:51

一种常见的解决方案是服务器端包含 (SSI),它允许您在多个页面中包含一个 html 标记块(除其他外)。如果您使用 PHP,请务必考虑 PHP 包含: http://www.w3schools.com/php /php_includes.asp

One common solution is Server Side Includes (SSI), which allows you to include one block of html markup in multiple pages (among other things). If you're using PHP, definitely consider PHP includes: http://www.w3schools.com/php/php_includes.asp.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文