I am having a random problem with my website. I am not sure if its just my internet connection that is causing this or if it is a problem with the website it self.

The prob is that randomly once in like every 5-6 visits, the website will take a long time to load. Normal load time is about 850ms. But when this random bug/glitch/problem/something happens, it will take about 5.5 seconds to load the page.

The site contains javascript, PHP randomizer, uses PHP's date() function and logs the visitors' IP address and time.

One by one I took out all of these and even then the bug occurs.

Try refreshing the page if it loads fine the first time and keep doing so and withing 10 refreshes you'll see what I'm talking about. (that is if the problem is not my internet)


Also, Google's dev tools tells me that everytime that 5.5 sec glitch occurs, my index page:

Send Request: GET
Total Heap Size: 11MB

Any idea what that means?

Dani AI

Generated

Intermittent long page loads that line up with the page’s load event are usually caused by a single resource or operation that sometimes stalls the main thread or the HTTP transfer. Since narrowed the symptom to the onload timing and observed slower loads correlated with one image variant, a focused diagnostic approach will reveal whether the delay is client-side (resource decode, blocking script, DNS) or server-side (slow TTFB, logging/file locks, external API call).

Recommended diagnostics:

  • Capture a Network waterfall and a Performance trace in DevTools to see which resource or phase is waiting or blocking the load event (Chrome DevTools Network docs).
  • Measure server TTFB from a shell:
    curl -s -w "%{time_starttransfer}\n" -o /dev/null https://example.com/

    Repeating that several times helps detect intermittent server-side delays.

Targeted fixes to try (non-exhaustive):

  • Avoid relying on window.onload to start UI logic; use DOMContentLoaded so scripts do not wait for all images to finish decoding. See the difference on MDN (DOMContentLoaded vs load). Example initialization pattern:
    document.addEventListener('DOMContentLoaded', function () {
      // init UI and attach listeners
    });
  • Defer or async noncritical scripts (see the defer/async script attributes) so parsing and rendering are not blocked.
  • Optimize images that appear to correlate with slow loads: compress, convert to efficient formats, set intrinsic size, or lazy-load below-the-fold images ().
  • Check for synchronous XHR or blocking JS in onload (synchronous XHR on the main thread is deprecated and can block the page; see MDN).

Server-side causes to inspect: file-append logging with exclusive locks, slow database writes, or synchronous external API calls. Correlating client traces with server logs (or adding a simple response-time header) will show whether the delay is in transport/server processing or in client-side resource handling.

Recommended Answers

All 3 Replies

On my computer it seems to take longer to load on the page loads where it shows the front view of the Blizzard-XI (the one with it pushing the soccer ball) than when it's showing the side/back perspective.

Hope that helps in some way :)

On my computer it seems to take longer to load on the page loads where it shows the front view of the Blizzard-XI (the one with it pushing the soccer ball) than when it's showing the side/back perspective.

Hope that helps in some way :)

Hmm, I should take out the image randomizer. Its not doing much anyways. Wow, I really don't get this problem! It makes me laugh...

Ok So the problem is in the firing of the onload(). Any ideas why that'd take long to kick start? Thats the reason why it shows my 11KB php file taking 5 seconds to download on DSL connection.

Still no clue on the solution.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.