Facebook Developers
DocsToolsSupportNewsApps
Log In
  • Social Plugins
  • Facebook Login
  • Open Graph
  • Facebook APIs
  • Games
  • Payments
  • App Center
  • Promote Your App
  • iOS
  • Android
  • JavaScript
  • PHP
  • More SDKs
  • Core Methods
    • FB.api
    • FB.init
    • FB.ui
  • Auth Methods
    • FB.getAuthResponse
    • FB.getLoginStatus
    • FB.login
    • FB.logout
  • Event Handling
    • FB.Event.subscribe
    • FB.Event.unsubscribe
  • XFBML
    • FB.XFBML.parse
  • Canvas Methods
    • FB.Canvas.Prefetcher.addStaticResource
    • FB.Canvas.Prefetcher.setCollectionMode
    • FB.Canvas.hideFlashElement
    • FB.Canvas.scrollTo
    • FB.Canvas.setAutoGrow
    • FB.Canvas.setDoneLoading
    • FB.Canvas.setSize
    • FB.Canvas.setUrlHandler
    • FB.Canvas.showFlashElement
    • FB.Canvas.startTimer
    • FB.Canvas.stopTimer

FB.Canvas.Prefetcher.addStaticResource

Tells Facebook that the current page uses a specified resource. This can cause that resource to be prefetched to the browser to improve performance.

See the Prefetching section of the Canvas tutorial for an overview of this feature.

Usage Scenarios

  • Resource not referenced from the DOM. By default, your application’s DOM for is traversed for object, link, and script tags that reference Flash, Javascript, and CSS files. If your static resource is one of these types, but is not referenced from the DOM, you can call this function to schedule it for prefetching.
  • Multiple page loads. If users commonly go through two page loads in your app, but only the second page load uses the resource, you may want to schedule the resource for prefetching in every page load to make sure that it gets fetched in the first page load, thus making the second load faster.

The resource must properly return the following HTTP headers when requested by the client (if the headers are specified at all):

  • Content-Type - Currently supported content types are application/x-shockwave-flash, application/x-compress, text/css, application/javascript, and application/x-javascript. If the content is not one of these types, the resource will be ignored.
  • Content-Length - Only the largest resources will be prefetched; if the size of the resource is not specified, it will be assumed to be 1K, which is unlikely to be large enough to be prefetched.
  • Cache-Control - if this is set to no-cache, no-store, or private, the resource will be ignored.
  • Vary - if this is set, the resource will be ignored.
  • Expires/Last-Modified - if there is too short a time between these two values, if only one is specified, or there is too short a time between the current time and one of these values, then the resource will be ignored.

You can use the staticresources connection on the Graph API Application object to verify that resources you are adding are getting counted.

Updated over a year ago
Facebook © 2013 · English (US)
AboutAdvertisingCareersPlatform PoliciesPrivacy Policy