浏览网站时保持与服务器的永久连接

发布于 2024-08-11 10:21:56 字数 527 浏览 2 评论 0原文

我们是一家年轻的初创公司,下周将推出一款独特的聊天产品。我们的聊天目前基于通过 BOSH(使用旁遮普语)的 Jabber(使用 Openfire 作为我们的 Jabber 服务器),并使用 jQuery 作为客户端脚本。

目前,当前设置最关键的问题是站点导航,当在我们网站的页面之间导航时,BOSH 连接会丢失,直到加载新页面且 BOSH 连接经过身份验证。由于这个问题,我们必须在注销未注销就离开我们网站的用户之前设置一个非常长的超时(大约 1 分钟)。

我们知道基于 javascript 锚点的导航解决方案,但实现此解决方案需要对我们网站的标记、CSS 和 JS 脚本进行许多更改,而且我们网站的结构非常复杂。

还有其他解决办法吗? 我正在考虑基于框架的导航,当一个页面将容纳 2 个 iframe 时 - 一个是隐藏的并保存 BOSH 连接,另一个保存真实的页面内容。这种解决方案的问题在于,它影响了用户的感觉,并且地址栏中的 URL 将始终保留包含框架的页面的 URL。

对于我们的问题,是否有任何解决方案不需要完全重写网站的结构/标记?

提前致谢!

We are a young start-up launching a unique chat product next week. Our chat is currently based on Jabber (using Openfire as our Jabber server) via BOSH (using Punjab), with jQuery for our client side scripts.

Right now our most critical issue with the current setup is with the site navigation, when navigating between pages in our web-sites the BOSH connection is lost until the new page is loaded and the BOSH connection is authenticated. Due to this issue we have to set a very big timeout (around 1 minute) before logging out users who have left our website without signing out.

We are aware of javascript anchor based navigation solutions, but implementing this would require many changes in our site's markup, CSS and JS scripts and our site's structure is very complicated.

Is there any other solution?
I was thinking about frame based navigation, when a page will hold 2 iframes - one is hidden and holds the BOSH connection, and one holds the real page content. the problem with this solution is that it affects the users' feel and the URL in the location bar will always stay the URL of the page that holds the frames.

is there any solution for our problem that will not require a complete rewrite of the site's structure/markup?

Thanks in advance!

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

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

发布评论

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

评论(3

紫轩蝶泪 2024-08-18 10:21:56

虽然这可能不是一个完整的重写,但我会说这需要一些工作。让聊天框保留在那里并在内容中使用ajax,即如果像在facebook上一样底部有聊天栏,则将其余部分放在您通过ajax页面进入的id中。换句话说,将聊天从布局中取出,将其单独放置,并将链接放入 ajax 请求中,这些请求可以通过全局链接处理程序进行处理,并通过 sed 搜索替换所有文件来替换链接。 (href =“更改为href =”javascript:urlhandler(但这需要考虑外部链接)
我能想到的另一个选择是在您的网站上有两个 iframe。主要和聊天。并为从页面、D/C 或发生在他们身上的任何事情进行导航的用户提供会话 cookie。

Though this might not be a complete rewrite I'll say it will take some doing. Have the Chat box stay there and ajax in content, i.e. if, like on facebook the bottom has the chat bar, section the rest in an id you ajax you pages into. In other words, take the chat out of your layout, put it separate, and make your links into ajax requests which can be handled via a global link handler and links substituted via a search a replace over all files via sed. (href=" changed to href="javascript:urlhandler( but this will need to account for external links)
The other option I can think of is having two iframes on your site. Main and chat. And provide Session cookies for those who navigate from the page, D/C or whatever will happen to them.

睫毛上残留的泪 2024-08-18 10:21:56

您是否在每个页面上都使用了聊天功能?如果是这样,答案是调整脚本的缓存。确保所有大型 JS 文件都是外部的,并且服务器未注册任何更改(例如:上次修改时间)。将图像组合成精灵。通过现有的众多缩小器之一运行您的代码。最后但并非最不重要的一点是,投资 CDN。 Amazon CloudFront 既简单又便宜:您会发现它对于提高性能有奇效。

Are you using an implementation of your chat on each page? If so, the answer is to tweak caching for your scripts. Make sure all large JS files are external and that the server registers no changes (e.g.: Last Modified). Combine images into sprites. Run your code through one of the many minifiers that exist. Last but not least, invest in a CDN. Amazon CloudFront is simple and cheap: you'll find that it works wonders for improving performance.

岁吢 2024-08-18 10:21:56

您可以使用jquery的历史插件(http://www.mikage.to/jquery/jquery_history.html )来处理后退和前进导航并通过ajax加载页面,就像您所说的那样。

像这样的东西应该有效(未经测试):

Page1.htm:

<html>
<head><title>Page 1</title></head>
<body>
     <div id="content">
         <a href="/page2.htm">Load Page 2</a>
     </div>
    <div id="chat"></div>
</body>
<script>
    $(function(){
        function loadPage(hash){
            if($.browser.msie) {
         hash = encodeURIComponent(hash);
        }
            $.ajax({
                "url":hash,
                "success":function(response){
                     var newPage = $(response);
                     document.title=newPage.find("title").html();
                     $("#content").html(newPage.find("#content").html());
                 }
            });
            return false;
        }
        $.historyInit(loadPage);
        $("a").live("click",function(){
            $.historyload(this.href);
        });
    });
</script>
</html>

Page2.htm:

<html>
<head><title>Page 2</title></head>
<body>
     <div id="content">
         <a href="/page1.htm">Load Page 1</a>
     </div>
    <div id="chat"></div>
</body>
<script>
    $(function(){
        function loadPage(hash){
            if($.browser.msie) {
         hash = encodeURIComponent(hash);
        }
            $.ajax({
                "url":hash,
                "success":function(response){
                     // this is just an example and not too efficient.
                     var newPage = $(response);
                     document.title=newPage.find("title").html();
                     $("#content").html(newPage.find("#content").html());
                 }
            });
            return false;
        }
        $.historyInit(loadPage);
        $("a").live("click",function(){
            $.historyload(this.href);
        });
    });
</script>
</html>

如果您想将工作外包给我,我很乐意提供帮助。 :o)

You can use jquery's history plugin (http://www.mikage.to/jquery/jquery_history.html) to handle back and forward navigation and load pages via ajax like you were talking about.

Something like this should work (untested):

Page1.htm:

<html>
<head><title>Page 1</title></head>
<body>
     <div id="content">
         <a href="/page2.htm">Load Page 2</a>
     </div>
    <div id="chat"></div>
</body>
<script>
    $(function(){
        function loadPage(hash){
            if($.browser.msie) {
         hash = encodeURIComponent(hash);
        }
            $.ajax({
                "url":hash,
                "success":function(response){
                     var newPage = $(response);
                     document.title=newPage.find("title").html();
                     $("#content").html(newPage.find("#content").html());
                 }
            });
            return false;
        }
        $.historyInit(loadPage);
        $("a").live("click",function(){
            $.historyload(this.href);
        });
    });
</script>
</html>

Page2.htm:

<html>
<head><title>Page 2</title></head>
<body>
     <div id="content">
         <a href="/page1.htm">Load Page 1</a>
     </div>
    <div id="chat"></div>
</body>
<script>
    $(function(){
        function loadPage(hash){
            if($.browser.msie) {
         hash = encodeURIComponent(hash);
        }
            $.ajax({
                "url":hash,
                "success":function(response){
                     // this is just an example and not too efficient.
                     var newPage = $(response);
                     document.title=newPage.find("title").html();
                     $("#content").html(newPage.find("#content").html());
                 }
            });
            return false;
        }
        $.historyInit(loadPage);
        $("a").live("click",function(){
            $.historyload(this.href);
        });
    });
</script>
</html>

If you would like to outsource the work to me I'd be glad to help. :o)

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