Defer JS [Deleted]

Here's an interesting side effect while using DeferJS.

If a site user uploads a text file which happens to be an HTML sample that contains script tags, DeferJS will resequence the script tags in that text attachment when others download it.

I tested using a very basic HTML sample that had script in the head section and upon download, the text file saved on my PC had the scripts moved to just before the closing body tag.

Surprising, and yet logical, I guess when you think through how it's working.

Do you think there be a way to have DeferJS not fire when in the attachment function in XenForo, kind of like you exempt ACP code?
 
@TJ Adams Ah, I've never thought about that (primarily since I don't allow html on attachment - relying on default setting). But considering how it's coded, it'll surely do that indeed. Anyway, I just did an edit to my add-on that utilizes this add-on's class so that it'll check the controller name. From what I can tell, attachments' controller name is XenForo_ControllerPublic_Attachment, and blacklisting that controller name for the JS deferring solves the issue (at least on my test).

If you feel comfortable with editing the DeferJS add-on's file by yourself, then do this:
Edit library/Jrahmy/DeferJs/Listener.php, and add the following line:
PHP:
if ($frontController->route()->getControllerName() === 'XenForo_ControllerPublic_Attachment') { return; }
To somewhere on frontControllerPostView function, as long as it's before the deferrer being called.
 
Excellent, that fixed the problem. Thank you.

I've never thought about that (primarily since I don't allow html on attachment - relying on default setting). But considering how it's coded, it'll surely do that indeed.
Yes, it was quite surprising to see when it was reported to me. Oh, it's not that we are allowing people to post HTML. These are just .TXT attachment uploads. People are sharing html and script samples with each other as forum attachments. They don't render as HTML, just download as text files.
 
Oh, it's not that we are allowing people to post HTML. These are just .TXT attachment uploads. People are sharing html and script samples with each other as forum attachments. They don't render as HTML, just download as text files.
Oh right, it will hit text files either way, as long as those files have <html on it.
 
@TJ Adams, thanks for reporting this issue. I will add @BobbyWibowo's patch to the official version shortly. I never stumbled across this myself, but it's essentially just because the add-on performs a regex search and replace on XenForo's output, even when the output is an attachment.

@rafass There's nothing more that needs to be done. You can view the source of your site to see for yourself if they were moved to the bottom. If they are and it's still being reported incorrectly, let me know and I'll look further into it.
 
@popr Screenshot or link? If the scripts don't behave well when deferred, there's not too much I can do.

You can blacklist some of the troublesome ones (and their dependencies, ie jQuery), but sometimes it's more trouble than it's worth.
 
Hello,

I have a Problem - when I cklick to send a message i have a big delay.
So look:
defered_01.webp

But Defer js is not aktiv:
upload_2015-9-7_8-4-32.webp

Any Idea whats wrong?
 
But these are 2 different things.
Deferred.php is a xenforo funktion.

Defer js move only the scripts at the end of the page.

How looks your settings here?

Screenshot_4.webp
 
Last edited:
I'm questioning whether or not this is working properly..... I'm using UI.X

The google insights is picking up on these scripts as being render blocking:-
xenforo.js
zloader.js (from bbcode and buttons manager)
funbox.min.js (from UI.X)
ie8_polyfill.js (from UI.X)
functions.min.js (from UI.X)

None of these scripts are blacklisted so can't think why the add on is not acting upon them. Any ideas @Jeremy P ?
 
@Rob provided that you can view the source of a page on your site, and all the javascripts (<script>) appear just before the </body> tag, the add-on is working as expected.

I'm clueless as to why PageSpeed Insights would be marking them as render blocking. On my own site with this add-on, no scripts show up in that list.
 
@Ryan Nielson I don't own a copy of that add-on, so I don't know if it works any differently, but I doubt it.

@xfrocks would be better suited to answer though, as he can view the source of this add-on, while I can't view the source of his.
 
@Ryan Nielson I don't own a copy of that add-on, so I don't know if it works any differently, but I doubt it.

@xfrocks would be better suited to answer though, as he can view the source of this add-on, while I can't view the source of his.
Thanks, I'll ask the same question there.

I installed this addon, and it doesn't appear to have changed anything in terms of my Google PageSpeed Insights. Is that normal? Am I missing something? The same 10 items are recommended to be deferred.

Code:
http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js
http://stratics.com/js/xenforo/xenforo.js?_v=9510fde7
http://stratics.com/…j/ams/jquery.bxslider.min.js?_v=9510fde7
http://stratics.com/…ngallery/min/media_slider.js?_v=1b06f603
http://stratics.com/…ark/functions.min.js?_v=9510fde7_1.4.7.1
http://stratics.com/…ault/resources/js/y/yui/yui-min.js?v=406
http://stratics.com/vault/resources/js/base.js?v=406
http://stratics.com/vault/resources/js/xf/base.js?v=406
http://stratics.com/vault/resources/js/bbcode.js?v=406
http://stratics.com/vault/resources/js/xf/bbcode.js?v=406
 
Viewing the HTML source of your site, several scripts are still in the <head> section. Others are before </body>, so it seems some are deferred while others aren't.

This add-on will defer all of them (except any matching the blacklist filters), so something else would probably be at play here, but I'm not sure what. It could be the two add-ons conflicting, or something to do with CloudFlare.
 
Top Bottom