Page 49 of 52

Re: [RC] Custom Code

Posted: Wed Apr 06, 2016 4:05 am
by John connor
I'm wondering if I could use this extension to defer JS in the extensions I have. Would the code go in overall_header_body_before? Please read here: viewtopic.php?p=14399621#p14399621

If this would work would my code look like this:

Code: Select all

<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
function downloadJSAtOnload() {
var element = document.createElement("script");
element.src = "defer.js";
document.body.appendChild(element);
}
if (window.addEventListener)
window.addEventListener("load", downloadJSAtOnload, false);
else if (window.attachEvent)
window.attachEvent("onload", downloadJSAtOnload);
else window.onload = downloadJSAtOnload;
</script>
</body>
</html>

Re: [RC] Custom Code

Posted: Wed Apr 06, 2016 7:58 am
by martti
John connor wrote:I'm wondering if I could use this extension to defer JS in the extensions I have. Would the code go in overall_header_body_before? Please read here: viewtopic.php?p=14399621#p14399621

If this would work would my code look like this:

Code: Select all

<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
function downloadJSAtOnload() {
var element = document.createElement("script");
element.src = "defer.js";
document.body.appendChild(element);
}
if (window.addEventListener)
window.addEventListener("load", downloadJSAtOnload, false);
else if (window.attachEvent)
window.attachEvent("onload", downloadJSAtOnload);
else window.onload = downloadJSAtOnload;
</script>
</body>
</html>
This extension does not work since phpBB 3.1.6. See the first post of this topic.
Also, put all your Javascript at the end of the page.

Re: [RC] Custom Code

Posted: Wed Apr 06, 2016 10:46 am
by John connor
Yes, I use insertemplate. Have since 3.1.6. The JS files I would like to defer are from extensions.

Re: [RC] Custom Code

Posted: Wed Apr 06, 2016 11:06 am
by martti
John connor wrote:Yes, I use insertemplate. Have since 3.1.6. The JS files I would like to defer are from extensions.
I've no other answer than what was already given to you in viewtopic.php?p=14399621#p14399496
Mick wrote:You should be asking in extension writers or wherever you got the code from.
Also, you can check if the cache headers are set for your Javascript files.

Re: [RC] Custom Code

Posted: Thu Apr 07, 2016 1:28 am
by John connor
I don't understand why they're saying that in my other post. I go here: https://varvy.com/pagespeed/ and this is what it says:


http://i.imgur.com/yrJYvP5.jpg

http://i.imgur.com/JCab2hz.jpg

The website recommends that I defer my JS files. If that HTML code could be converted to PHP then perhaps I would add it to the bottom of index.php?

I was told to clarify my question at Stack Exchange as well. I can defer JS in Wordpress!

BTW, I run an anti-hacker script so I have to temp disable it otherwise this won't work at the page speed site. So don't no one try this with my site. It more than likely won't work.

Re: [RC] Custom Code

Posted: Thu Apr 07, 2016 4:53 am
by martti
John connor wrote:I don't understand why they're saying that in my other post. I go here: https://varvy.com/pagespeed/ and this is what it says:


http://i.imgur.com/yrJYvP5.jpg

http://i.imgur.com/JCab2hz.jpg

The website recommends that I defer my JS files. If that HTML code could be converted to PHP then perhaps I would add it to the bottom of index.php?

I was told to clarify my question at Stack Exchange as well. I can defer JS in Wordpress!

BTW, I run an anti-hacker script so I have to temp disable it otherwise this won't work at the page speed site. So don't no one try this with my site. It more than likely won't work.
The screendump you give says there are many Javascript files. Not that they need to be deferred.

Re: [RC] Custom Code

Posted: Thu Apr 07, 2016 11:07 am
by John connor
It would be nice to defer the scripts that website shows though. I've done this in WordPress. There must be a way to do this is phpBB.

Re: [RC] Custom Code

Posted: Thu Apr 07, 2016 11:23 am
by martti
John connor wrote:It would be nice to defer the scripts that website shows though. I've done this in WordPress. There must be a way to do this is phpBB.


The Javascript should already be at the end.

The site suggests to put together the javascript code in one file, called defer.js. This will not be possible in phpBB without doing ugly things.

Btw. the code you gave is mostly the same as:

Code: Select all

<script src="defer.js" defer></script>

Re: [RC] Custom Code

Posted: Fri Apr 08, 2016 12:05 pm
by John connor
No. That is NOT correct. Read here: https://varvy.com/pagespeed/
3. Change the "defer.js" to the name of your external JS file.
I should be able to do this:

Code: Select all

<script type="text/javascript">
function downloadJSAtOnload() {
var element = document.createElement("script");
element.src = "https://systechforum.net/ext/paybas/breadcrumbmenu/styles/all/template/breadcrumb-menu.js";
document.body.appendChild(element);
}
if (window.addEventListener)
window.addEventListener("load", downloadJSAtOnload, false);
else if (window.attachEvent)
window.attachEvent("onload", downloadJSAtOnload);
else window.onload = downloadJSAtOnload;
</script>

But if you read that link....it's to be placed in a HTML document.

Re: [RC] Custom Code

Posted: Sun Apr 10, 2016 7:58 pm
by GoBieN
Of course it should, Javascript is part of HTML pages.

You can use the inserttemplates (see 1st post of this topic) extension to add the Javascript code at event below footer or something like that, which would insert the Javascript code in the HTML at the bottom of the page.

But if you want to do this for all javascript files from phpBB and extensions then you will have lots of work and it probably won't be worth it.

Re: [RC] Custom Code

Posted: Mon Apr 11, 2016 1:05 am
by John connor
Yeah, I tried adding the defer script to one of the headers and cleared the cache for each test, but it didn't look like the scripts were deferred.

I have been using customcode and inserttemplate for a year just to let you know.

Re: [RC] Custom Code

Posted: Mon Apr 11, 2016 8:21 pm
by GoBieN
Customcode doesn't work on 3.1.8 anymore, but if you have used to as you say, you should have no trouble doing the things you want.

Re: [RC] Custom Code

Posted: Mon Apr 11, 2016 11:53 pm
by John connor
I know it doesn't I have been using inserttemplate since custom code no longer worked.

Re: [RC] Custom Code

Posted: Fri Apr 15, 2016 2:52 pm
by TriKe27
Hi martti,

will there be an update for this extensions that it will work with phpBB >3.1.6? I would love to use it in the future (without workarounds etc.).

Greetings
Martin

Re: [RC] Custom Code

Posted: Fri Apr 15, 2016 7:15 pm
by martti
TriKe27 wrote:Hi martti,

will there be an update for this extensions that it will work with phpBB >3.1.6? I would love to use it in the future (without workarounds etc.).

Greetings
Martin
No, there won't be.