treehouse : what would you like to learn today?
Web Design Web Development iOS Development

[Solved] Speed up load time on wordpress blog

  • Hi,

    After going round a few forums asking for reviews of my site, one problem keeps coming up. The load time of my site is too slow..

    How can I speed this up?

    I just recently added a 3D map to my site which contains the following in the header

    </script>
    <script type=\"text/javascript\" src=\"http://www.google.com/jsapi?key=ABQIAAAAVAE9M7VMhVDVBrQ49_7gWRTwZS8tmoUVJtNGQUK4FnzblpgaHBS4UWU620Cy04XAQuKeYLOdn6wSzA\"></script>
    <script type=\"text/javascript\">

    google.load(\"earth\", \"1\");
    google.load(\"maps\", \"2.99\"); // For JS geocoder

    var ge = null;
    var geocoder;

    function init() {
    geocoder = new GClientGeocoder();
    google.earth.createInstance(\"map3d\", initCB, failureCB);
    }

    function initCB(object) {
    ge = object;
    ge.getWindow().setVisibility(true);
    ge.getNavigationControl().setVisibility(ge.VISIBILITY_SHOW);

    GDownloadUrl(\"http://www.leehughes.co.uk/wp-content/leehughes.xml\", function(data, responseCode) {
    var xml;

    if (window.ActiveXObject) {
    xml = GXml.parse(data);
    fParsed = xml.parsed;
    } else if (window.DOMParser) {
    var parser=new DOMParser();
    xml=parser.parseFromString(data,\"text/xml\");
    fParsed = true;
    }

    var pages = xml.documentElement.getElementsByTagName(\"page\");

    // Create Grundlefly style map for placemark
    var normal = ge.createIcon('');
    normal.setHref('http://www.grundlefly.com/images/grundlefly_placemarker_gmaps.png');
    var iconNormal = ge.createStyle('');
    iconNormal.getIconStyle().setIcon(normal);
    var highlight = ge.createIcon('');
    highlight.setHref('http://www.grundlefly.com/images/grundlefly_placemarker_gmaps.png');
    var iconHighlight = ge.createStyle('');
    iconHighlight.getIconStyle().setIcon(highlight);
    var styleMap = ge.createStyleMap('');
    styleMap.setNormalStyle(iconNormal);
    styleMap.setHighlightStyle(iconHighlight);

    // Create Standard style map for External Travel web page placemarks
    var normal2 = ge.createIcon('');
    normal2.setHref('http://www.grundlefly.com/images/external_placemarker.png');
    var iconNormal2 = ge.createStyle('');
    iconNormal2.getIconStyle().setIcon(normal2);
    var highlight2 = ge.createIcon('');
    highlight2.setHref('http://www.grundlefly.com/images/external_placemarker.png');
    var iconHighlight2 = ge.createStyle('');
    iconHighlight2.getIconStyle().setIcon(highlight2);
    var styleMap2 = ge.createStyleMap('');
    styleMap2.setNormalStyle(iconNormal2);
    styleMap2.setHighlightStyle(iconHighlight2);


    for (var i = 0; i < pages.length; i++) {
    var ptag = pages[i].getAttribute(\"pageTag\");
    var externalPage = pages[i].getAttribute(\"externalPage\");
    var pageLink = pages[i].getAttribute(\"alternatePageLink\");


    if (!((ptag == \"Region\") || (ptag == \"Country\") || (ptag == \"State\") || (ptag == \"Area\"))) {
    var placemark = ge.createPlacemark('');

    // decide which placemark icon to use
    if (externalPage == \"yes\") {
    placemark.setStyleSelector(styleMap2);
    } else {
    placemark.setStyleSelector(styleMap);
    }

    // Create placemarker title
    var title = pages[i].getAttribute(\"title\");
    placemark.setName(title);

    // Extract some stuff from the XML file - I wish I didn't have to extract 3 x times
    // but not sure of any other way to do it / reference this info in statements below
    // Logic would suggest that I should only have to do this once
    var id = pages[i].getAttribute(\"id\");
    var title = pages[i].getAttribute(\"title\");
    var summary = pages[i].getAttribute(\"summary\");

    // Create point
    var lat = pages[i].getAttribute(\"lat\");
    var lng = pages[i].getAttribute(\"lng\");
    var point = ge.createPoint('');
    point.setLatitude(parseFloat(lat));
    point.setLongitude(parseFloat(lng));
    placemark.setGeometry(point);
    createPlacemark(placemark, id, title, summary, pageLink, externalPage);
    }
    }
    });
    }

    function createPlacemark(placemark, id, title, summary, pageLink, externalPage) {
    var currentPlacemark = placemark;
    var keyword = id;
    var titlename = title;
    var short_summary = summary;
    var alternateURL = pageLink;
    var externalLink = externalPage;

    ge.getFeatures().appendChild(currentPlacemark);

    google.earth.addEventListener(placemark, \"click\", function(event) {
    // Suppress default placemark balloon on click event
    event.preventDefault();

    // Create our own customn html balloon instead on click
    var b = ge.createHtmlDivBalloon('');
    b.setMaxWidth(800);
    b.setFeature(currentPlacemark);

    var div = document.createElement('DIV');

    if (alternateURL == \"\") {
    div.innerHTML = \"<div style=\\"font-size:10pt;width: 20em;\\"><div style=\\"position: relative; float: left; padding-right:10px;\\"><a href='\" + keyword + \".html' target='_parent'><img src='images/\" + keyword + \"_square2.jpg'></a></div><a href='\" + keyword + \".html' target='_parent'>\" + titlename + \"</a> - \" + short_summary + \"</div>\";

    } else {
    if (externalLink == \"no\") {

    div.innerHTML = \"<div style=\\"font-size:10pt;width: 20em;\\"><div style=\\"position: relative; float: left; padding-right:10px;\\"><a href='\" + alternateURL + \"' target='_parent'><img src='images/\" + keyword + \"_square2.jpg'></a></div><a href='\" + alternateURL + \"' target='_parent'>\" + titlename + \"</a> - \" + short_summary + \"</div>\";
    } else {
    div.innerHTML = \"<div style=\\"font-size:10pt;width: 20em;\\"><div style=\\"position: relative; float: left; padding-right:10px;\\"><a href='\" + alternateURL + \"' target='_blank'><img src='images/\" + keyword + \"_square2.jpg'></a></div><a href='\" + alternateURL + \"' target='_blank'>\" + titlename + \"</a> - \" + short_summary + \"</div>\";
    }
    }

    b.setContentDiv(div);
    ge.setBalloon(b);

    // Set a timeout function to close the InfoBalloon after 6 seconds
    // window.setTimeout(function() { ge.setBalloon(null); }, 6000);

    });

    return currentPlacemark;
    }

    function failureCB(object) {
    alert('load failed');
    }

    function submitLocation() {
    var address = document.getElementById('address').value;
    geocoder.getLatLng(
    address,
    function(point) {
    if (point && ge != null) {
    var la = ge.createLookAt('');
    // 40000 number being the zoom-to view altitude for those interested
    la.set(point.y, point.x, 100, ge.ALTITUDE_RELATIVE_TO_GROUND,
    0, 0, 40000);
    ge.getView().setAbstractView(la);
    }
    }
    );
    }

    </script>

    </head>
    <script type=\"text/javascript\" language=\"javascript\">
    function initMap() {
    init();
    P7_ExpMenu();
    }
    </script>


    Am guessing this will slow the page load time alot ?

    Also this contains something like 70 validation errors..

    Am thinking of getting rid of this as I don't fancy attempting to fix the errors and to view the map you need to install a google plugin which I doubt strangers would do just to view it.

    any other things that could be slowing down my page?

    Thanks

    http://www.leehughes.co.uk

    http://www.leehughes.co.uk/3d-route/


    thanks
  • It's bad for two reasons:

    1) As you've noticed, it totally slows the website down, and

    2) Some people (probably the majority), won't have the Google Earth plugin (like me, for example). So I waited and waited only to have something tell me that I couldn't view it.

    If you want to have it, put it on a special page that people can go to, certainly not the index.
  • Hi,

    Due to the way the code is done.. I have to put it in the header which basically means that every page that is viewed would have to scan through this code..

    Just wondering how much this would slow down the page..

    Looks like I will have to loose it :(
  • Nay nay.

    Just create a new template specific for the page that will have the map on it. Only put the JS in that template.
  • Am such a idiot!!!
  • "leehughes" said:
    Am such an* idiot!!!
    lol.. dont blame yourself.. even I never thought of it that we could put the required javascripts in the respected templates rather than including them in the header! Thanks a ton TheDoc! ;)