astroid-framework
astroid-framework copied to clipboard
The "Minify HTML advanced" option remove the first slash in path of the images
I activated the option "Minify HTML Advanced" in my template, to delete HTML comments. But that deletes images from the page. Looking closer, I noticed that this option deletes the first slash in the img tag
img src = "/images/folder/myimage.jpg"
BECOMES: img src = "images/folder/myimage.jpg"
That changes the relative URL, and the images disappear. (Idem on Windows and Linux server)
I found the code of this this option in the following file "libraries\astroid\framework\library\astroid\Document.php" I noticed that this problem was caused by the $ns1 variable at line 432. It is a too complex regex for me.
While waiting for a solution to be found, I solved my problem in an incorrect, but radical way. I simply canceled the variable like this> $ns1 = '';
Now the minification may not be complete, but I have no more comments or excess spaces. And the paths of my images are not destroyed.
I thought it could also come from the SEF of Joomla 4, but I found nothing on this subject. If this is not the case, I think you will find a more elegant solution than mine to modify this regex. Thanks.
I @FrenchLab47 I just test on Joomla 4 — Last Astroid on this test website on both Template Zero & One and I didn’t encounter the problem? Note: Joomla is only URL Search Engine Friendly & Rewrite Url http://joom4-astro.graf-test.ca/
I use almost everything in the Astroid compression possibilities... — LazyLoad Images (All Images) — Minify CSS — Minify HTML Advanced — Even Minify JS
With All that, the galaxy image in the website still appear under that URL —> src="http://joom4-astro.graf-test.ca/images/sampledata/cassiopeia/nasa1-1200.jpg"
I also Try ONLY — Minify HTML Advanced I also try with Joomla set at GZIP compression + — Minify HTML Advanced
The image src should normally appear with the full domain url, (http://yourwebsite.com/images....) something is changing that?
Do you have an URL where I can check?
Thank you for taking an interest in my question.
The image of your test site is OK, and there is no problem on the home page. (currentUrl = sitebase) The defect occurs with SEF in the other pages.
To start, here is a person who observed the same thing as me. https://stackoverflow.com/questions/33627910/joomla-3-broken-relative-url-addressing-images
And the answer he received is very clear:
"its about the image path. for example: /images/image1.jpg refers to image in /website-rootfolder/images/image1.jpg but images/image1.jpg refers to: currentUrl/images/image1.jpg So with slash it means: load image from /root without slash it means: load image from /current url"
I observe the same behavior on my site, with SEF activated. Everything works well when the slash is present in front of the path of images. I just noticed that your script deletes this slash when the "HTML Advanced" option is activated.
My site https://swingraf.com currently works with your modified script as I described it in my first post.
Please note: This behavior is not verifiable on the home page (currentUrl = sitebase)
But if you open any page with images, you can see this Slash in the console of your browser. If you delete this first slash, the image disappears, and you will find that the link is no longer good:
Example: ht-tps://swingraf.com/images/folder/***.jpg (good)
becomes ht-tps://swingraf.com/index.php/menu-categorie/images/***.jpg
It would simply be enough that your "Minify Advanced" option does not delete this first slash.
Cordially.
Yep you where right @FrenchLab47
The url should be something like
src="/images/name_of_image.jpg"
and the trailing slash is remove on images when using —> HTML Minify Level —> Advanced
I mark it as a bug. I know all these compression scheme are sometime a bit buggy or difficult to make them work properly, but it should not do that in this case.
Happening on my front page on my test website —> http://joom4-astro.graf-test.ca/ and also in inner page —> http://joom4-astro.graf-test.ca/article-4 Both images are curiously showing but the trailing slash is gone.
Hi @FrenchLab47 and @Chacapamac,
I fixed this issue in developer branch. Please help me download Developer branch and retest on your site. Please let me know if you need further assistant.
Thanks & Best Regards, Sonny
Hi @sonvnn, I downloaded the Developer branch, and updated. Then I checked if the images were not affected, and everything is fine. I haven't looked at the other fix yet.
Thank you for your work. Best regards. Patrick.
Just tested the Dev Branch The backslah on images URL is not truncated anymore even with HTML Minify Level > Advanced