Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8701031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:17:59+00:00 2026-06-13T02:17:59+00:00

MyNamespace.Facebook.coffee: namespace ‘MyNamespace’, (exports) -> exports.FacebookAPILoader = class constructor: (@appId, @channelFileUrl) -> @init() init:

  • 0

MyNamespace.Facebook.coffee:

namespace 'MyNamespace', (exports) -> 
    exports.FacebookAPILoader = class 

        constructor: (@appId, @channelFileUrl) -> 
            @init()

        init: (fbAPILoadedCallback) -> 
            #FB triggers/calls window.fbAsyncInit() after the API javascript loads: 
            window.fbAsyncInit = () => 
                @initFb()
                fbAPILoadedCallback() if fbAPILoadedCallback?
                return
            @loadAPI()

        loadAPI: () -> 
            ((d) ->
                id = 'facebook-jssdk'
                ref = d.getElementsByTagName('script')[0]
                return if d.getElementById id

                js = d.createElement 'script'
                js.id = id
                js.async = true
                js.src = "//connect.facebook.net/en_US/all.js"
                ref.parentNode.insertBefore js, ref
            )(document)

        # Set app specific settings here: 
        initFb: () -> 
            fbConfig = 
                appId: @appId
                channelUrl: @channelFileUrl
                status: true
                cookie: true
                xfbml: true
            FB.init fbConfig 

This is how I load the api in my views:
//MyView.cshtml:

@using (Script.Foot()) {
    var settingsReader = new System.Configuration.AppSettingsReader();
    var facebookAPIAppId = settingsReader.GetValue("Facebook_API_AppId", typeof(string));
    var hostName = settingsReader.GetValue("EnvHostname", typeof(string));

<script type="text/javascript">
    var myFb;
    $(document).ready(function () {
        myFb = new MyNamespace.FacebookAPILoader(
            '@Html.Raw(facebookAPIAppId)'
            , '//@Html.Raw(hostName)/modules/myapp/channel.html'
        );
    });
</script>
}

Jquery is loaded just before the closing </body> tag. I have two questions:

  1. Is there anything wrong with the way I am loading it here? I believe it will load asynchronously after jquery fires the document ‘ready’ event — is that correct? Is there a way to do it that has better performance?

  2. What is the best way to set this module up so that I can pass in arbitrary callbacks that will execute within fbAsyncInit()? I’m using this inside a CMS (Orchard) driven website, and I can potentially have multiple views in the same HTTP request wanting to add their own custom callbacks that should be run as part of fbAsyncInit(). How do I accomplish that? I know I could just pass in a callback array, but the part I’m not sure about is how to make sure all the different features on a given page can chime in on what their Facebook related code is, and how to ensure that the FacebookAPILoader.init() runs only after all those FB widgets’ callbacks and DOM elements and everything are ready to interact with it.

UPDATE:
I think I’m going to do this the same way google analytics async tracking does it with the _gaq variable in the global namespace. Any code that needs facebook API interaction can push callbacks into the _gaq style queue, and the FacebookAPILoader module will pull that queue when it’s ready. Is this a naive approach? Is there any danger that my code will try to add to the _gaq style queue AFTER fbAPILoadedCallback() has already been called?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T02:18:00+00:00Added an answer on June 13, 2026 at 2:18 am

    I found this, which I think is the best solution I’ve come across for this problem so far. A little easier to implement than the _gaq style queue, as long as you don’t mind depending on jQuery.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

// MyClass.h namespace MyNamespace { static const double GasConstant = 1.987; class MyClass {
namespace MyNameSpace { static class MyClass { static MyClass() { //Authentication process.. User needs
Suppose I have the following defined in a header file: namespace MyNamespace { Class
Consider the following: namespace MyNamespace{ class MyClass { public: // Public area private: //
In trying to compile this program: namespace MyNamespace { template<typename T> class Test {
namespace MyApp.MyNamespace { public class MyClass:System.Web.UI.Page { private DataUtility Util = new DataUtility(); private
Lets say I have the following class: namespace myNamespace { [TypeLibType((short)2)] [ClassInterface((short)0)] [ComImport] public
namespace MyNamespace { static void foo1() { } } using namespace MyNamespace; class MyClass
I use DataContract with ObservableCollection: [DataContract(Namespace = Terms.MyNamespace)] public class MyContract { internal MyContract
I have something like this: namespace MyNamespace { public partial class MyClass: UserControl {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.