Mon. - Fri. 9 am - 5 pm Ask a Question
Remember me

Problem when importing external javascript libraries and putting code optimization

1 week 22 hours ago #1

  • Juan Vilar's Avatar
  • Juan Vilar
  • Posts: 24
Hi all! I just discovered a big issue in my website that i'd like to share with you.

Not long ago, I decided to write coding tutorials in my website . A part of those codes I write down in gist gist.github.com/

What I do is I copy the code into a gist and then embed it via HTML code into my articles.



Up to here everything is fine. However. at some point. i decided to activate javascript optimisation and deferred loading. in the performance bar.




however, the problem now is that, since when I embed these fists, the embed code is a <script> tag, Gridbox is automatically taking all of the scripts and putting them in the end of the webpage.







this renders all of the article reading as very useless and pointless.

What can I do to fix this? is there any way to tell gridbox not to defer / optimize these scrips so they stay where they are? any cheat or trick ?

1 week 22 hours ago #2

  • Juan Vilar's Avatar
  • Juan Vilar
  • Posts: 24
i believe this to be the problem. Can I disable somehow the combination of javascript files from within the article so this doesn't happen? it would be very helpful.

thanks

1 week 2 hours ago #3

  • Vyacheslav's Avatar
  • Vyacheslav
  • Posts: 9577
Hello,
Thank you for contacting us

You need to disable deferred loading


Best Regards,
Vyacheslav, Balbooa Support Team

5 days 14 hours ago #4

  • Juan Vilar's Avatar
  • Juan Vilar
  • Posts: 24
well, that I already know, but then the code blocks the javascript and google ranks my website less because of this feature being disabled.
is there some way , some class or something we can add so it doesn't get imported ?

3 days 7 hours ago #5

  • Vyacheslav's Avatar
  • Vyacheslav
  • Posts: 9577
Unfortunately, this is not possible.

Best Regards,
Vyacheslav, Balbooa Support Team

3 days 5 hours ago #6

  • Juan Vilar's Avatar
  • Juan Vilar
  • Posts: 24
Hi Vyacheslav. First of all thank you for the quick response and your commitment to this software. This software is amazing.

Secondly, don't tell me this is not possible. of course it is!! We just need some tweaking and hacking for it to happen. We were able to put people on the moon, we surely can do this.

I don't want to put the burden on you guys so i'd like to try to do it myself. However I've been inspecting the code that is responsible for this and I still haven't dared to do this properly.

What I want to do is put a tag in the js scripts to allow for the parser to ignore these scripts. (or a class) that will ignore all of this.

I don't want to put you guys in the burden of having to do this. Would you point me what file / controller is in charge of this? I'll inspect it and tweak it myself (if you guys don't mind)

Again, thank you so much for the support. I love gridbox.

3 days 4 hours ago #7

  • Vyacheslav's Avatar
  • Vyacheslav
  • Posts: 9577
You need at the gridbox.php(components/com_gridbox/helpers/gridbox.php)

in function :
setDeferredLoading($body)
replace:
foreach (pq('script') as $value) {
to
foreach (pq('script')->not('.custom-class') as $value) {
but after the update it will be lost

Best Regards,
Vyacheslav, Balbooa Support Team

2 days 21 hours ago #8

  • Juan Vilar's Avatar
  • Juan Vilar
  • Posts: 24
Thank you so much . I applied the patch as you told me and named the class as "exclude-deffer"
then, I ran into my SQL explorer / editor and ran the following query:

update jos_gridbox_pages set params = REPLACE (params,"<script", "<script class='exclude-deffer'") WHERE page_category != 0;

I then enabled the deffer scripts and it works like a charm. I inspect the HTML code and the class exclude-deffer shows and it is not deferred until the very end of the website.

However. whenever I try to edit the article using the wysiwyg article editor, I click on the gist and the class exclude-deffer doesn't show up. It just show the gist as I posted it originally, without the class, despite the fact that in the front end it does show up.

2 days 21 hours ago #9

  • Juan Vilar's Avatar
  • Juan Vilar
  • Posts: 24
I'll show you a little about this small code poltergeist.
this is how the website looks after I executed the code snippet as I mentioned before


as you can see, the class exclude-deffer shows up.
then, I click on the red planetary gearbox icon to access the edit interface and click over the custom HTML



the class has disappeared. why? is there some sort of parser that removes this?
thanks for the help, very quick, I'll keep looking into it.

2 days 8 hours ago #10

  • Vyacheslav's Avatar
  • Vyacheslav
  • Posts: 9577
Hello,
Thank you for contacting us

The Gridbox does not delete anything,
Perhaps this is done by the codemirror editor.

Best Regards,
Vyacheslav, Balbooa Support Team
Powered by Kunena Forum