[3.2][BETA] Custom Code

A place for Extension Authors to post and receive feedback on Extensions still in development. No Extensions within this forum should be used within a live environment!
Get Involved
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

IMPORTANT: Extensions Development rules

IMPORTANT FOR NEEDED EVENTS!!!
If you need an event for your extension please read this for the steps to follow to request the event(s)
User avatar
John connor
Registered User
Posts: 1800
Joined: Fri Nov 14, 2014 5:14 pm
Location: U S Of A
Contact:

Re: [RC] Custom Code

Post by John connor » Wed Apr 06, 2016 4:05 am

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>

User avatar
martti
Registered User
Posts: 682
Joined: Thu Jul 31, 2014 8:23 am
Location: Belgium

Re: [RC] Custom Code

Post by martti » Wed Apr 06, 2016 7:58 am

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.

User avatar
John connor
Registered User
Posts: 1800
Joined: Fri Nov 14, 2014 5:14 pm
Location: U S Of A
Contact:

Re: [RC] Custom Code

Post by John connor » Wed Apr 06, 2016 10:46 am

Yes, I use insertemplate. Have since 3.1.6. The JS files I would like to defer are from extensions.

User avatar
martti
Registered User
Posts: 682
Joined: Thu Jul 31, 2014 8:23 am
Location: Belgium

Re: [RC] Custom Code

Post by martti » Wed Apr 06, 2016 11:06 am

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.

User avatar
John connor
Registered User
Posts: 1800
Joined: Fri Nov 14, 2014 5:14 pm
Location: U S Of A
Contact:

Re: [RC] Custom Code

Post by John connor » Thu Apr 07, 2016 1:28 am

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.

User avatar
martti
Registered User
Posts: 682
Joined: Thu Jul 31, 2014 8:23 am
Location: Belgium

Re: [RC] Custom Code

Post by martti » Thu Apr 07, 2016 4:53 am

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.

User avatar
John connor
Registered User
Posts: 1800
Joined: Fri Nov 14, 2014 5:14 pm
Location: U S Of A
Contact:

Re: [RC] Custom Code

Post by John connor » Thu Apr 07, 2016 11:07 am

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.

User avatar
martti
Registered User
Posts: 682
Joined: Thu Jul 31, 2014 8:23 am
Location: Belgium

Re: [RC] Custom Code

Post by martti » Thu Apr 07, 2016 11:23 am

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>

User avatar
John connor
Registered User
Posts: 1800
Joined: Fri Nov 14, 2014 5:14 pm
Location: U S Of A
Contact:

Re: [RC] Custom Code

Post by John connor » Fri Apr 08, 2016 12:05 pm

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.

User avatar
GoBieN
Registered User
Posts: 530
Joined: Fri Mar 05, 2004 5:22 pm
Location: Belgium
Contact:

Re: [RC] Custom Code

Post by GoBieN » Sun Apr 10, 2016 7:58 pm

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.

User avatar
John connor
Registered User
Posts: 1800
Joined: Fri Nov 14, 2014 5:14 pm
Location: U S Of A
Contact:

Re: [RC] Custom Code

Post by John connor » Mon Apr 11, 2016 1:05 am

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.

User avatar
GoBieN
Registered User
Posts: 530
Joined: Fri Mar 05, 2004 5:22 pm
Location: Belgium
Contact:

Re: [RC] Custom Code

Post by GoBieN » Mon Apr 11, 2016 8:21 pm

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.

User avatar
John connor
Registered User
Posts: 1800
Joined: Fri Nov 14, 2014 5:14 pm
Location: U S Of A
Contact:

Re: [RC] Custom Code

Post by John connor » Mon Apr 11, 2016 11:53 pm

I know it doesn't I have been using inserttemplate since custom code no longer worked.

TriKe27
Registered User
Posts: 18
Joined: Wed Feb 25, 2015 6:30 pm

Re: [RC] Custom Code

Post by TriKe27 » Fri Apr 15, 2016 2:52 pm

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

User avatar
martti
Registered User
Posts: 682
Joined: Thu Jul 31, 2014 8:23 am
Location: Belgium

Re: [RC] Custom Code

Post by martti » Fri Apr 15, 2016 7:15 pm

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.

Post Reply

Return to “Extensions in Development”

Who is online

Users browsing this forum: FinStar, koraldon, Mathieu M., nou nou, panhead and 40 guests