仅使用客户端模板和 Rest 调用的单个 HTML 站点

发布于 2024-11-10 04:33:43 字数 329 浏览 6 评论 0原文

我正在开发一个高度动态的网站,该网站有大约 10 个不同的页面(登录、注册、我的服务、我的个人资料等)。

我正在考虑使用 javascript 模板框架(例如 jquery-temp)并将所有页面存储在一个 html 文件中。用户交互将触发不同模板的交换/激活/隐藏。在服务器端,所有请求都通过rest/json 调用进行管理。我认为 html 将由 nginx 提供服务,而 json 调用将定向到 jetty (java)。

这是一种可行的方法吗?可能会出现什么问题?

谢谢,

编辑 - 我知道该怎么做,我想知道这从长远来看是否会导致问题。

I am working on a highly dynamic site which has around 10 different pages (login, registration, my services, my profile, etc.).

I am thinking of using a javascript template framework (e.g., jquery-temp) and store all the pages in one single html file. User interactions will trigger swapping/activating/hiding of different templates. On the server side, all the request are managed through rest/json calls. I am thinking that the html will be served by nginx while the json calls are directed to jetty (java).

Is this a viable approach and what can go wrong ?

Thanks,

EDIT - I know how to do this, I want to know if this is will cause a problem in the long run.

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

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

发布评论

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

评论(2

白云不回头 2024-11-17 04:33:43

我最近也在做类似的事情,而且效果还不错。一些观察结果:

  1. 如果您希望不同的视图具有可链接的 url,并维护历史记录,那么您需要比其他情况更加努力,以便浏览器后退/前进按钮可以正常工作。 (尽管您可能不关心这一点)
  2. 当用户第一次访问该网站时,您会加载一个大的前端页面 - 可能比拆分页面慢。
  3. 站点缓存没有粒度;如果您更改网站某一页面上的一个字符,则需要重新加载整个内容。与如果您将页面溢出并随后更改其中一个页面相比,任何 HTTP 缓存对于其他页面来说仍然没问题。
  4. 通过 AJAX 切换模板可能会给您带来比标准页面加载稍少的 UI 反馈,例如,如果连接速度很慢,单击常规链接至少会显示页面正在加载,而 AJAX 调用会在后台旋转。我不确定这是否适用于您的情况,因为听起来您将预加载所有 HTML,然后只需切换哪些位可见。类似地,通过 AJAX 填充内容的页面在加载时可能会不太优雅地呈现。
  5. 显然 - 如果用户没有打开 javascript,那么你就完蛋了。我不确定是否有人关心这个,但我想这也可能会影响搜索引擎优化。

I've been doing something similar recently, and it's working out pretty well. Couple of observations:

  1. You'll need to work harder than you otherwise would if you want the different views to have linkable url's, and maintain history so things'll work okay with the browser back/forward buttons. (although you might not care about that)
  2. You've got one big upfront page load when the user first visits the site - could be slower than splitting the pages out.
  3. There's no granularity to the site caching; if you change one character on one page in the site, the whole thing needs to be reloaded. In contrast to if you spilt the pages out and later change one of the pages, any HTTP caches will still be okay for the other pages.
  4. Switching templates via AJAX might give you slightly less UI feedback than standard page loads, EG if the connection is slow, clicking on a regular link would at least show me that the page is loading, wheras an AJAX call would be spinning away in the background. I'm not sure this'd apply in your case tho as it sounds like you'll have all the HTML pre loaded and just switch which bits are visible. In a similar vein pages which populate their content via AJAX might render less gracefully whilst they are loading.
  5. And obviously - If the user doesn't have javascript turned on, you're screwed. I'm not sure if anyone cares about this anymore, but I guess it might also impact SEO.
无风消散 2024-11-17 04:33:43

我看到的问题是:如果你提供来自不同域的模板和数据,跨域请求仍然是一个令人头痛的问题。但是您可以根据路径使用 nginx 或专用代理服务器将请求代理到一台服务器或另一台服务器,例如从 example.com/html 提供 html 并从 example.com/rest 提供数据。

The problem I can see: if you serve templates and data from different domains, cross-domain requests are still a headache. But you can proxy requests to the one server or another using nginx or dedicated proxy server depending on the path, for example serve htmls from example.com/html and data from example.com/rest.

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