策略问题:RESTful 应用程序中的平面/静态页面

发布于 2024-12-08 14:04:38 字数 529 浏览 1 评论 0原文

我正在使用 Backbone.js 通过 tastypie 连接到 Django 后端。我已经为我的动态内容弄清楚了一些事情,但我想知道如何处理我的常见问题解答/关于/联系页面。因为我希望获得不间断的用户体验,无需等待链接之间的页面加载,所以我想知道从哪里加载这些平面页面的数据。

我不想在这里进行过度架构,因为这些是包含非动态内容的小册子页面。简而言之,布局很重要,他们不需要 CMS。

那么我的主index.html 中是否已经有这些页面,并且只在需要时显示它们?这对我来说似乎很肮脏。

我是否让 Django 将这些页面的 html 存储在设置为接受 html 的 Textarea 中,并在需要时通过 tastypie 将 html 作为 JSON 吐出?呃,这对我来说也很脏。

或者是一个混合体,其中 django 只吐出相关数据来填充已经在我的index.html中定义的html——这听起来是正确的,但是工作量太大了,我不想为这样的页面定义数据库模型我已经说过,不需要 CMS。

我希望我对所有这些方法都偏离了基础,并且你有更好的方法来解决我的困境。

I'm using Backbone.js to connect to a Django backend via tastypie. I've got things figured out for my dynamic content, but I am wondering what to do about my FAQ / About / Contact pages. Because I want to have an uninterrupted user experience, no waiting for the page to load in between links, I'm wondering where to load the data for these flat pages from.

I don't want to overarchitect here, because these are brochure pages with non-dynamic content. In short, layout is important, and they don't need a CMS.

So do I have the pages already in my main index.html, and just show them when needed? This seems dirty to me.

Do I have Django store the html for these pages in a Textarea set up to accept html, and spit the html out as JSON through tastypie when needed? Ugh, that sounds dirty to me too.

Or a hybrid where django only spits out the relevant data to fill in the html that's already defined in my index.html-- This sounds correct, but like way too much work, I don't want to define db models for pages that as I've said, don't need a CMS.

I'm hoping I'm way off base with all these approaches, and you have something much better to solve my dilemma.

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

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

发布评论

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

评论(1

相思碎 2024-12-15 14:04:38

您的第一个想法是将它们包含在主 index.html 中并根据需要显示它们似乎相当合理,但有几个缺点:

  • 您的索引页面较重,因此加载速度比所需的速度慢
  • 您的小册子页面在逻辑上没有分开在您的代码库中,

您可以通过在加载index.html后动态加载它们的HTML来修复这两个问题。当用户单击页面时,您仍然会使用相同的客户端代码来显示页面,就好像它嵌入到主 HTML 文件中一样,但不是将 HTML 包含在初始的 index.html 文件中...

<div id="faq-page">
   <h1>FAQ</h1>
   ...
</div>

具有空白div 和一个在主页呈现后通过 AJAX 加载它们的事件。我不确定您是否使用 jquery,但如果使用,代码将如下所示

<div id="faq-page"></div>
<script>
    $(function() {
        $("#faq-page").hide() // ensure it doesn't display too early
                      .load("/include/faq.html");  // async load the content from server
    });
</script>

现在,当用户点击应用程序中的常见问题解答链接时,页面将尽快显示。如果页面有时间加载(通常),它将立即显示。如果他们碰巧在加载之前点击了链接,那么服务器响应后就会显示该链接。

您可以根据需要在服务器端设置 /include/faq.html

Your first idea of including them in the main index.html and showing them as needed seems quite reasonable, but has a couple drawbacks:

  • Your index page is heavier and thus slower to load than it needs to be
  • Your brochure pages aren't logically separated in your codebase

You can fix both of these by having the HTML for them loaded dynamically after the index.html loads. You'd still use the same client-side code to show the pages when the user clicks to them as if it were embedded in the main HTML file, but instead of including the HTML in the initial index.html file...

<div id="faq-page">
   <h1>FAQ</h1>
   ...
</div>

have blank divs and an event to load them through AJAX after the main page has rendered. I'm not sure if you're using jquery, but if so, the code would look like this

<div id="faq-page"></div>
<script>
    $(function() {
        $("#faq-page").hide() // ensure it doesn't display too early
                      .load("/include/faq.html");  // async load the content from server
    });
</script>

Now when the user hits the FAQ link in your app, the page will appear as fast as possible. If the page has had time to load (normally) it will show up instantly. If they happen to hit the link before it's loaded, it will show up as soon as the server responds.

You set up /include/faq.html however you'd like on the server side.

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