tracy
tracy copied to clipboard
Not working for AJAX request during initial page load
I am implementing Tracy in Phalcon project and I have ran into difficulties with AJAX requests. The setting is that there is page which loads multiple "snippets" from backend.
If there is an exception in the snippet two different situations occure:
- (During first page load) text exception is rendered instead of the "snippet"
- (Afterwards) normal bluescreen is triggered and showed.
Investigation (for the lack of documentation) led me to the conclusion that Tracy is initialized at the end of page, so all AJAX requests before won't be handled via bluescreen.
Can something be done with it? Can do Tracy initialization on the page start?
Maybe this cdd9777066cda7be3193edc82720a75a55624a45 can help you. Call <?php Tracy\Debugger::renderLoader() ?>
in head, preferably before others CSS & scripts are loaded:
<!DOCTYPE html>
<html>
<head>
<title>...<title>
<?php Tracy\Debugger::renderLoader() ?>
<link rel="stylesheet" href="assets/style.css">
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
</head>
It works! However I had to delete the async
as this caused to work only randomly (based on the time of loading)...
There are two options:
- Make it optionally (see commit diff)
- Remove it completely
I have done the first option and also improved documentation slightly as I was looking for this when implementing it in our non Nette project.
Diff (with txt extension because of GitHub)
Edit: noticed that static variant of method need also the param to pass it.
@repli2dev thanks for diff!
Moving Tracy's `
- you need to track AJAX requests during initial page load
- Tracy is loaded slowly, because there is some blocking or slow script or style in the page and browser is waiting
But Tracy can be blocking script too. It uses session, so it blocks until whole page is sent to browser (and session is closed). So ideal solution is to add attribute async
, it perfectly solves 2). Without async it may the impression of page loading make worse.
But async
doesn't solve 1). Even worse, with async you cannot count on the fact that Tracy will be loaded before event 'DOM ready' #250.
So I am not sure how to solve it.
Yes, I see the dilema as I was feeling the same implementing the patch and that's why I implemented the turn off of async as optional.
However I would probably be OK, with previous behaviour when Tracy (by default) was loaded synchronously at the end of body... and when some would need to catch ajax request to tracy during page load (like me) then they would include the code in header and decided async
themselves.