The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript 404 error with my deferred javascript

  • This topic is empty.
Viewing 1 post (of 1 total)
  • Author
  • #201469

    I’ve been tweaking my website lately to make it load a bit faster.

    I stumbled across an old article to defer external javascript and I thought I might apply it with the facebook like button seeing as it takes its time to load.

    So I created a new js file, called it fbdefer and added this to it:

    (function(d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) return;
    js = d.createElement(s); = id;
    js.async=true; js.src = "//";
    fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));

    I then added it to the header of my wordpress with:

    <div id="fb-root"></div>
    <script type="text/javascript">
    function deferJSWordPress() {
    var element = document.createElement("script");
    element.src = "/fbdefer.js";
    if (window.addEventListener)
    window.addEventListener("load", deferJSWordPress, false);
    else if (window.attachEvent)
    window.attachEvent("onload", deferJSWordPress);
    else window.onload = deferJSWordPress;

    It all works fine, and it loads the buttons after the page has loaded. But when I do speed tests, they all return 404 errors relating to that file.

    Any clues?

    Thank you

Viewing 1 post (of 1 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.