The difference between your first and second approach is that for the first approach the user needs to load the page first and in your second approach (server retrieving the webpage), the user doesn't have to load the page (because the server does that).
If it's allowed to make the user first visit the page, then you can also use some additional approaches:
You can make your script notify the server by an AJAX request for example (so the client notifies the server that the script has loaded). The disadvantages of this method are:
- Always sends an AJAX request (if it's only required once it might be a useless overhead)
- Problems may occur with cross domain requests (they can be solved)
Another way is that you intercept all calls to the server (can be done with a reverse proxy) and keep logs of the Referrer
header (contains the page that requested the script). But similar to your conclusion, this adds an additional overhead.
I think the conclusion is that it's hard to prevent an additional overhead (either on the server or the client), the only exception is of course the server retrieving the page (your second idea with curl
). So in the end that might be the best solution.