load position of cookie script
-
Hi
is there a way to load the cookie in «adaptive-images-front.php» right after the <head> tag? I wouldn’t interfere with external css loaded.
I guess it would make sense to do so, since the cookie’s job has a higher priotity than css.
regards
theo
-
Well, right now I am using the
wp_headhook to load this bit of Javascript. This is the recommended way that requires nothing by the user. In order to achieve what you propose I could register some new hook of my own, but then the user would have to add some code in the place they need it manually. And that would have the risk that this place might even be wrong. So, as fas as I can understand it, the current way is the safest way! 🙁However, to be honest, I am not sure I understand the purpose of your proposal. What would one achieve by it?
Hi Nevma
Thanks for the answer.
The purpose is simple.
For instance on GTMetrix, the script in adaptive-images-front.php often is identified as a blocking script.The recommendation says:
The following inline script blocks were found in http://www.xydomain.ch/ between an external CSS file and another resource. To allow parallel downloading, move the inline script before the external CSS file, or after the next resource.
Inline script block #1 (that’s the code from adaptive-images-front.php)If the script could be moved to the top, it wouldn’t block anything.
It’s not a big thing. I was just wondering if it was possible to alter the position.regards
theoAh, good point!
Well this kind of script is indeed “blocking” in the theoretical sense, but what it does is so tiny that it actually takes no time to proceed in any normal device. The recommendation is correct! But it is meaningful for bigger scripts.
The thing is that the script will remain “blocking” in any place we put it! Unless we load it asynchronously or load it near the closing of the </body>.
Hi Nevma
It is only blocking in the head when the script is between two link tags. I’ve tried it. But nevermind, it’s too small to bother.
Thanks for your interest.
Have a nice weekend.
theoIndeed it it way too small! And even if we did bother, the solution would be to add a custom hook, as I mentioned earlier, which would require some coding by the user every time they installed the plugin. This would not be very nice. So, I guess the balance weighs towards keeping things as they are.
Thank you for your suggestions and let me know if there is anything else you need!
Cheers,
TakisNo, everythings ok.
Thanks for your care.
regards
theoMy pleasure!
🙂
Hi Nevma
After a good rest, i tried, just for the heck of it, the following test:
In my functions.php i wrote://remove adaptive image cookie from head remove_action( 'wp_head', 'adaptive_images_front_head_cookie_javascript', 0 );In my header.php i wrote right after <head> :
<!--noptimize--><script type = "text/javascript">var screen_width = screen.width;var devicePixelRatio = window.devicePixelRatio ? window.devicePixelRatio : 1;document.cookie = 'resolution=' + screen_width + ',' + devicePixelRatio + '; path=/';</script> <!--/noptimize-->I tested the code and to my surprise it works well.
The plugin does its work and the recommendation is gone.This test cannot be recommended for imitation for it lacks the conveniance the plugin offers in the backend. The script has to be updated manually and this is easily forgotten.
I wish you a pleasant weekend.
theoHi, Theo,
Well, you got it right! What you did should indeed work, although I would guess that this would be a blocking script as well. But all the other issues we have discussed previously still stand.
A nice weekend to you, too!
Cheers,
Takis
The topic ‘load position of cookie script’ is closed to new replies.