facebook iframe 应用程序 - 如何组织和编写代码以加快页面加载 - PHP SDK

发布于 2024-12-14 09:43:50 字数 513 浏览 2 评论 0原文

我正在 Facebook iframe 中编写一个应用程序,但不确定如何最好地编写它。我最初在主 canvas.php 文件中编写了所有代码,但发现在结果加载到 iframe 之前一切都运行得太慢。

然后我尝试使用 php 标头定位方法来尝试将不同的页面加载到 iframe 中,从而减少页面加载时间。但是,标头位置将被忽略。

我还尝试使用 javascript 使页面加载到 iframe 中,这确实会加载到新页面中,但页面遇到很多问题。它不会使用 $_GET 将参数传递给自身。

基本上,当画布页面首次加载到 iframe 中时,我需要执行一些检查,然后重定向到另一个文件,以避免在每个页面加载时执行检查,因为这会严重显示所有内容。然后,我需要使用 URL 中的不同参数重新加载页面,以使用不同的结果填充 iframe,这又非常慢,因为它必须再次执行所有检查。

因此,如何才能像 facebook iframe 中的普通网站一样实现流畅的工作流程?

[编辑] 只是想 Ajax 是一个有效的选择吗?

非常感谢。

I am writing an app within a facebook iframe and am unsure how best to write this. I originally wrote all the code within the main canvas.php file but found everything was running too slow before results were being loaded into the iframe.

I then tried using the php header location method so to try and load different pages into the iframe, thus reducing page load time. However, the header location is ignored.

I have also tried using javascript to get the page to load within the iframe instead, this does load in the new page but the page experiences lots of problems. It wil not pass parrameteres to itself using $_GET.

Basically, I need to perform some checks when the canvas page is first loaded in the iframe and then re-direct to another file to avoid the checks being perfomed on every page load as this seriously shows everything down. I then need to have page reloads with different parrameteres in the URL to populate the iframe with different results, again this is very slow as it has to perfomr all the checks again.

Therefore, how can I achieve a smooth workflow as a normal site within a facebook iframe?

[EDIT] Just thought is Ajax a valid option?

Many thanks in advance.

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

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

发布评论

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

评论(1

帥小哥 2024-12-21 09:43:50

由于没有指定channelURL,大多数人都会遇到响应时间慢的情况。请参阅http://developers.facebook.com/docs/reference/javascript/

频道文件

通道文件解决了跨域通信的一些问题
在某些浏览器中。 channel.html 文件的内容可以是
单行:

频道文件的缓存时间很重要
可能的。提供此文件时,您必须发送有效的 Expires 标头
有效期较长。这将确保通道文件
由浏览器缓存,这对于流畅的用户体验非常重要。
如果没有适当的缓存,跨域通信将变得非常困难
速度很慢,用户的体验会严重下降。一个简单的
在 PHP 中执行此操作的方法是:

channelUrl 参数是可选的,但建议使用。提供一个
通道文件可以帮助解决三个特定的已知问题。第一的,
包含跨框架通信代码的页面可能会导致社交
没有channelUrl 时显示为空白的插件。二、如果没有
提供了channelUrl并且页面包含自动播放音频或
视频时,用户可能会听到两个音频流,因为页面有
后台二次加载跨域
沟通。第三,通道文件将防止包含额外的内容
服务器端日志中的点击次数。如果您不指定channelUrl,则
可以删除包含 fb_xd_bust 或 fb_xd_fragment 的页面视图
日志中的参数以确保正确计数。

channelUrl 必须是与页面匹配的完全限定 URL
您包含 SDK。换句话说,通道文件域
如果您的网站使用 www 提供服务,并且您修改了,则必须包含 www
您的页面上的 document.domain 必须使用相同的 document.domain
也更改channel.html 文件。协议还必须
匹配。如果您的页面通过 https 提供,则您的channelUrl 也必须是
https。请记住使用脚本 src 的匹配协议作为
出色地。上面的示例代码使用了协议相关的 URL,应该
正确处理大多数 https 情况。

Most people experience slow response times due to not having a channelURL specified. See http://developers.facebook.com/docs/reference/javascript/

Channel File

The channel file addresses some issues with cross domain communication
in certain browsers. The contents of the channel.html file can be just
a single line:

It is important for the channel file to be cached for as long as
possible. When serving this file, you must send valid Expires headers
with a long expiration period. This will ensure the channel file is
cached by the browser which is important for a smooth user experience.
Without proper caching, cross domain communication will become very
slow and users will suffer a severely degraded experience. A simple
way to do this in PHP is:

The channelUrl parameter is optional, but recommended. Providing a
channel file can help address three specific known issues. First,
pages that include code to communicate across frames may cause Social
Plugins to show up as blank without a channelUrl. Second, if no
channelUrl is provided and a page includes auto-playing audio or
video, the user may hear two streams of audio because the page has
been loaded a second time in the background for cross domain
communication. Third, a channel file will prevent inclusion of extra
hits in your server-side logs. If you do not specify a channelUrl, you
can remove page views containing fb_xd_bust or fb_xd_fragment
parameters from your logs to ensure proper counts.

The channelUrl must be a fully qualified URL matching the page on
which you include the SDK. In other words, the channel file domain
must include www if your site is served using www, and if you modify
document.domain on your page you must make the same document.domain
change in the channel.html file as well. The protocols must also
match. If your page is served over https, your channelUrl must also be
https. Remember to use the matching protocol for the script src as
well. The sample code above uses protocol-relative URLs which should
handle most https cases properly.

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