0

I have weird issue, I tried to google but couldn't find the reason for this behavior.

before you click on a link, turn on the firebug or chrome network tab

Issue: My initial ajax request prevents the first load of my website.. it starts working only after the refresh.

http://vetosports.com/designer/index.html

you can see that no document.ready and window.load events are ever fired on the first load... As soon as you refresh page, everything works correctly

you can see in the network tabs that it gets stuck on designhandler.php... The code for sending request to designhandler.php is:

var urlFetch = "designhandler.php"
$.ajax({
    type: "POST",
    url: urlFetch,
    dataType: 'json',
    cache: false,
    data: {
        sport: chosenSport
    },
    success: function(resp){
        mainData=resp;
        console.log(mainData); // in the console I can see the correct response
        var jArr = resp.garments.jersey.designs;
        var socArr = resp.garments.socks.designs;
        var shoArr = resp.garments.shorts.designs;

        for (jID in jArr) {
            if (jArr[jID]['default'] == "y") {
                globalJID = jID;
            }
            if (jArr[jID]['featured'] == "y") {
                featArr.push(jID);
            }
        }
        for (socID in socArr) {
            if (socArr[socID]['default'] == "y") {
                globalSocID = socID;
            }
        }
        for (shoID in shoArr) {
          if (shoArr[shoID]['default'] == "y") {
            globalShoID = shoID;
          }
        }

        fLayers = mainData.garments.jersey.designs[globalJID]['frontLayerCount'];
        bLayers = mainData.garments.jersey.designs[globalJID]['backLayerCount'];

    }
});

Any idea what am I doing wrong? this is a big issue and I can't leave it like this.

Thanks, Tom

Tomasz Golinski
  • 743
  • 5
  • 25
  • I've got something similar and had no solution: http://stackoverflow.com/questions/16812741/firebug-lite-for-chrome-spoils-hover-effect-and-mouseover-event maybe you can find a clue... – k102 Jan 22 '14 at 12:46
  • have you tried to see what happens when the data is cached? Is it the length of time it takes for the page to respond which is causing the load issue? – Liam Sorsby Jan 22 '14 at 12:46
  • There is defiantly some caching issue with your code. Some values aren't set till the first load and are setting up after refresh. Just confirmed it try Cntrl + F5 on your page. – Rajesh Dhiman Jan 22 '14 at 12:50
  • @Liam I'm not sure how to check it... I'm not sure what causes it tbh... – Tomasz Golinski Jan 22 '14 at 12:51
  • @RajeshDhiman I have been thinking of that but all the variables used in the actual AJAX request are defined just before the AJAX code – Tomasz Golinski Jan 22 '14 at 12:53
  • Yeah you def need to set up caching for thous asset files, 12 seconds to load on a 76Mb line, could become unusable for 70% of the world. 95% mobile users, nice site though – Lawrence Cherone Jan 22 '14 at 12:54
  • @LozCherone could you please elaborate? The thing is, when I refresh, it loads in 2-3 seconds (on 2Mb line)... the initial load makes it impossible to do anything.. :/ – Tomasz Golinski Jan 22 '14 at 12:59
  • You could enable caching with your ajax request but also you could enable caching using your htaccess caching your json however as this is produced using php not sure this would cache the json. Another method may be to cache your results using memcache or memcached and add this into your designhandler.php script to check and return the result which would increase the speed of script – Liam Sorsby Jan 22 '14 at 13:04

1 Answers1

0

It is not actually stuck on designhandler.php

It looks like the problem is after that. One would have to look to see what you are doing after that to spot the issue.

A good advice - log different stages in your server side script and see at which point things fail to continue.

Hope that helps

Hamster
  • 680
  • 7
  • 23
  • I see what the problem could be.. my `$(window).load()` starts before the preload.js even sends and receives the response from ajax ... yet not sure why it do it like that only on the initial start of the website – Tomasz Golinski Jan 22 '14 at 13:32
  • throw some alerts around your JS to see what runs and what doesn't. However I am still inclined to think that your problem could well be server-side. – Hamster Jan 22 '14 at 14:18