动态填充主页内容?

发布于 2024-09-06 06:39:22 字数 182 浏览 3 评论 0原文

是否有任何理由不让网页动态检索其主要内容?

例如,我有一个具有页眉和页脚的页面,并且该页面的中间是一个空的 div。当您单击标头中的按钮之一时,会在幕后完成 http GET,并且空 div 的 .innerHTML() 会被结果替换。

我想不出为什么这可能是一个坏主意,但我似乎找不到任何页面可以做到这一点?请指教!

Is there any reason to NOT have a webpage retrieve it's main content on the fly?

For example, I have a page that has a header and a footer, and in the middle of this page is an empty div. When you click on one of the buttons in the header, an http GET is done behind the scenes and the .innerHTML() of the empty div is replaced with the result.

I can't think of any reason why this might be a bad idea, but I can't seem to find any pages out there that do it? Please advise!

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

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

发布评论

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

评论(6

小霸王臭丫头 2024-09-13 06:39:22

这并非闻所未闻,但存在问题。

  • 显而易见的是,一些用户出于安全原因关闭了 javascript,他们将根本无法使用您的网站。

  • 它还会对使用屏幕阅读器等辅助技术的残障用户产生负面影响。

  • 它会使浏览器更难有效地缓存您的静态内容,从而降低浏览体验。

  • 它会使搜索引擎更难将您的内容编入索引。

  • 它可能导致后退和前进按钮停止工作,除非采取特殊步骤使其工作。

    它可能导致后退和前进

  • 调试问题也相当烦人,尽管如果您使用 Firebug 之类的工具,当然并非不可能。

    调试问题也相当烦人,尽管如果

我不会将它用于静态内容(普通网页),但对于动态更新的内容来说,这无疑是一种合理的方法。

It's not unheard of, but there are issues.

  • The obvious one is that some users have javascript turned off for security reasons, and they will not be able to use your site at all.

  • It can also negatively impact handicapped users that are using assistive technology such as a screen reader.

  • It can make it harder for the browser to effectively cache your static content, slowing down the browsing experience.

  • It can make it harder for search engines to index your content.

  • It can cause the back and forward buttons to stop working unless to take special steps to make them work.

  • It's also fairly annoying to debug problems, although certainly not impossible if you use a tool such as Firebug.

I wouldn't use it for static content (a plain web page) but it's certainly a reasonable approach for content that is dynamically updated anyway.

蘸点软妹酱 2024-09-13 06:39:22

如果您不需要额外的工作,它就会杀死后退和前进历史按钮,并且很难链接到每个按钮加载的页面。您必须实现某种 URL 更改机制,例如通过在 URL 的哈希中对最后单击的页面进行编码(例如,当您单击按钮时,您将重定向到 #page-2 或其他内容)。

它还会使禁用 JavaScript 的用户无法访问您的网站。良好网页设计的原则之一是“优雅降级”——使用 JavaScript、Flash 或 CSS 等高级功能增强您的网站,但即使它们被禁用,它们仍然可以工作。

Without extra work on your part it kills the back and forward history buttons, and it makes it difficult to link to the pages each button loads. You'd have to implement some sort of URL changing mechanism, for example by encoding the last clicked page in the URL's hash (e.g. when you click a button you redirect to #page-2 or whatever).

It also makes your site inaccessible to users with JavaScript disabled. One of the principles of good web design is "graceful degradation"--enhancing your site with advanced features like JavaScript or Flash or CSS but still working if they are disabled.

情深缘浅 2024-09-13 06:39:22

两个注意事项:搜索引擎优化 (SEO) 和书签。

是否有直接的 URL 可以访问您的标题链接?如果是这样,你(几乎)没问题。例如,以下代码既适合 SEO,又可以根据您的需要填充您的页面:

<a href="seoFriendlyLink.html" onclick="populateOnTheFly(); return false;">Header Link</a>

当人们尝试为他们通过 JavaScript 加载的页面添加书签时,就会出现问题……这种情况不会发生。您可以将大部分潜在的推文、电子邮件推荐和头版 Digg/Reddit 文章扔出窗外。普通用户不知道如何链接到您的内容。

Two considerations: Search engine optimization (SEO) and bookmarks.

Is there a direct URL to access your header links? If so, you're (almost) fine. For example, the following code is both SEO friendly and populates your page as you desire:

<a href="seoFriendlyLink.html" onclick="populateOnTheFly(); return false;">Header Link</a>

The catch occurs when people attempt to bookmark the page they've loaded via JavaScript... it won't happen. You can throw most of those potential tweets, email referrals, and front page Digg/Reddit articles out the window. The average user won't know how to link to your content.

云淡月浅 2024-09-13 06:39:22

你在哪里读到这是一个坏主意?是否动态填充内容完全取决于要求。然而,在大多数情况下,内容不是随页面一起加载的,但如果您需要动态加载内容,那么这应该不是一个坏主意。

如果您的内容是通过 javascript 加载的,并且用户浏览器上禁用了 javascript,那么绝对这是一个坏主意

Where did you read it is a bad idea? It purely depends on requirements whether or not content will be populated on-the-fly. In most cases, however, the content is loaded along with the page not on-the-fly but if you need your content on-the-fly, it shouldn't be a bad idea.

If your content is loaded via javascript and javascript is disabled on users' browser then definitely it is a bad idea.

烟火散人牵绊 2024-09-13 06:39:22

我也想不出有什么不好的原因(除了可能的 SEO),一件事可能是一个好主意,那就是只加载一次数据。即

<a href="javascript: showdiv1()">Show Div1</a> - do ajax/whatever only if the innerhtml is blank

<a href="javascript: showdiv1()">Show Div2</a> - do ajax/whatever only if the innerhtml is blank

<div1></div>
<div2></div2>

这应该会降低服务器负载,因此 div 内容仅加载一次。

干杯

I cant think of a bad reason for this either (other than possibly SEO), one thing that would probably be a good idea is to load the data only once. ie

<a href="javascript: showdiv1()">Show Div1</a> - do ajax/whatever only if the innerhtml is blank

<a href="javascript: showdiv1()">Show Div2</a> - do ajax/whatever only if the innerhtml is blank

<div1></div>
<div2></div2>

This should keep the server load down so the divs content is only loaded once.

Cheers

甜嗑 2024-09-13 06:39:22

这是启用 ajax 的站点中相当标准的行为。

但请记住,需要付出额外的努力:

  • 确保后退按钮正常工作
  • 链接到(和书签)特定内容
  • 支持禁用 JavaScript 的浏览器。

This is pretty standard behavior in ajax enabled sites.

Keep in mind however that extra effort will be needed to:

  • ensure the back button works
  • link to (and bookmark) specific content
  • support browsers with javascript disabled.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文