헬로쿠의 샘플 앱에있는 페이스 북 앱에 표준 Facebook 자바 스크립트 코드를 사용하고 있습니다. 나는 그것을 이해하지 못했지만 조심스럽게 샘플 애플리케이션을 수정하여 나에게 유용한 몇 가지 기본 작업을 수행 할 수 있었다.왜 Facebook Javascript SDK가 비동기 적으로로드 되었습니까?
이 코드는 어떻게 든 Facebook 자바 스크립트 SDK를로드합니다. 즉, 자바 스크립트 코드 파일을로드합니다. 실제로 어떤 파일이로드됩니까? 다른 자바 스크립트 코드 파일을로드하는 것처럼 왜 그냥로드 할 수 없습니까? 예를 들어 :
<script type="text/javascript" src="/javascript/jquery-1.7.1.min.js"></script>
이 매우 복잡한 방법의 단점은 내가 그것의 머리 또는 꼬리를 만들 수 없다는 것입니다, 나는 그것을 이해하지 않기 때문에, 나는 그것을 사용하는 방법에 대한 더 직관이 없습니다. 여기
코드 :가 페이스 북의 서버의 응답을 기다릴 필요가 없기 때문에
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({
appId : '<?php echo AppInfo::appID(); ?>', // App ID
channelUrl : '//<?php echo $_SERVER["HTTP_HOST"]; ?>/channel.html', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
// Listen to the auth.login which will be called when the user logs in
// using the Login button
FB.Event.subscribe('auth.login', function(response) {
// We want to reload the page now so PHP can read the cookie that the
// Javascript SDK sat. But we don't want to use
// window.location.reload() because if this is in a canvas there was a
// post made to this page and a reload will trigger a message to the
// user asking if they want to send data again.
window.location = window.location;
});
FB.Canvas.setAutoGrow();
};
// Load the SDK Asynchronously
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
Facebook 자바 스크립트 SDK가 실제로 다른 자바 스크립트 코드에 사용되지 않는 경우 왜이 기술을 사용해야합니까? –
페이스 북은 스크립트가 수백만 개의 웹 페이지에 삽입되는 큰 플레이어 중 하나이므로 성능 문제에 더 많은주의를 기울여야합니다. 그리고 주위를 둘러 보니 다른 빅 플레이어들이 일반적으로 스크립트를 비동기 적으로 임베드하는 것이 좋습니다. 구글, 트위터, ... – CBroe
그리고 페이 스북 (Facebook)의 경우 서버가 잠시 느려질 수 있습니다. 같은 버튼이로드 될 때주의를 기울여야합니다. 일반적으로 약간의 지연이 있습니다. – Tom