MyBB Community Forums

Full Version: Better management of Javascript and Updates
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi Team,
I have a feedback based on inline js, js versions and template updates used in MyBB such as on templates described below. I will take differences from MyBB 1.8.13 and previous generation.
Let us take example of below templates :-
postbit,postbit_classic templates Showthread_rating javascript, search_results_threads_thread, search_results_posts_post
We have similar javascript elemente where we use onclick Event
href="{$mybb->settings['bburl']}/misc.php?action=whoposted&tid={$thread['tid']}" onclick="MyBB.whoPosted({$thread['tid']}); return false;">
I am not completely against inline js, but I feel the above can be managed with DOM.

And in various places, we use versions of js. Example newreply, newthread we use 1813 version for post.js.
<script type="text/javascript" src="{$mybb->asset_url}/jscripts/post.js?ver=1808"></script>
In MyBB 1.8.13 ->
<script type="text/javascript" src="{$mybb->asset_url}/jscripts/post.js?ver=1813"></script>


And for rating.js, we use 1808
<script type="text/javascript" src="{$mybb->asset_url}/jscripts/rating.js?ver=1804"></script>
In MyBB 1.8.13,we use

<script type="text/javascript" src="{$mybb->asset_url}/jscripts/rating.js?ver=1808"></script>
The above are example templates and there are more.

This I feel is inconsistent and for theme developers who have to provide theme updates. There is a problem with MyBB updates to provide template updates :-
  • where users have lots of different plugins and they are required to update themes[High]
  • lots of different versions of js for different javascripts which can cause theme break as well
  • changes in inline js as well, for example MyBB.whoPosted was previously part of link as onclick

I feel that if the above issues can be handled, it will be great help for everyone who uses different theme from default MyBB theme.
If it is not part of MyBB 1.8 series, probably for MyBB 2.0, it will be awesome.

Thanks for reading and thanks for providing regular updates Smile
The version parameters change when a JS file is edited in a version. So if the "ver=1813", the JavaScript file was last updated in 1.8.13. If "ver=1808", the JS file was last updated in 1.8.8. This is to try and bust caches of JS files when upgrades occur.

Inline JS is certainly annoying, and IMO using event listeners would be a better decision.
(2017-11-13, 06:39 PM)Euan T Wrote: [ -> ]The version parameters change when a JS file is edited in a version. So if the "ver=1813", the JavaScript file was last updated in 1.8.13. If "ver=1808", the JS file was last updated in 1.8.8. This is to try and bust caches of JS files when upgrades occur.
I will suggest making it consistent so that for upgrade 1.8.13, all js gets changed to 1813 so that it is consistent all over the board with other js. Than it will be easier for all theme owners to update their theme by just doing a search and replace of all js.

(2017-11-13, 06:39 PM)Euan T Wrote: [ -> ]Inline JS is certainly annoying, and IMO using event listeners would be a better decision.
Yes, that's what I feel.
Updating every version number for all JS files will result in far more template changes, making it even harder for theme authors to work out what templates they need to edit. Surely that would be an even worse solution?

In the future I really want to see JS loaded with a proper asset loader and not sprinkled about inside templates at all. That way JS scripts can be loaded in a single place (before the closing </body>) and we can look at adding JS management within the theme management interface. That could happen with 1.10 if somebody adopts that feature.
Euan, OP can correct me if I am wrong, but I feel the issue that is being reported is when the same JavaScript file is included in different places with different versions:

[Image: BHAMKyD.png]
It could simply be somefile.js?ver=${mybb->version} (not sure if that variable actually exists, just an example). It would bust the cache everytime you update your board, even when it's not necessary, but - updates don't happen all that often, and it removes all that noise in the templates (a variable does not need template updates - but of course you'd need these updates to put the variable in now...).

The only case where it causes problems is when you do an update that does not bump the version number, which shouldn't happen but MyBB has a bit of a history of doing.

If you want to take an extra step, stop using the version number altogether and instead make it some {$jsbump} which could be customizable in the ACP (same as cookie prefix), so admins can also trigger JS updates globally, in case they customize any of the javascript code.
(2017-11-14, 10:24 PM)Euan T Wrote: [ -> ]Updating every version number for all JS files will result in far more template changes, making it even harder for theme authors to work out what templates they need to edit. Surely that would be an even worse solution?

In the future I really want to see JS loaded with a proper asset loader and not sprinkled about inside templates at all. That way JS scripts can be loaded in a single place (before the closing </body>) and we can look at adding JS management within the theme management interface. That could happen with 1.10 if somebody adopts that feature.
If the js version is same, then I believe with just Find and Replace tool, it will be easier to update. Plus if you see frostschutz suggestion, it can even be controlled with a variable so theme author will not have to modify it each time.

(2017-11-14, 11:16 PM)Wildcard Wrote: [ -> ]Euan, OP can correct me if I am wrong, but I feel the issue that is being reported is when the same JavaScript file is included in different places with different versions:

[Image: BHAMKyD.png]
Issue is a little different, but because of various number of javascript, it is possible some places can have same javascript then different version which can cause future bugs. And yes, it is a definite problem as well.

(2017-11-15, 12:02 AM)frostschutz Wrote: [ -> ]It could simply be somefile.js?ver=${mybb->version} (not sure if that variable actually exists, just an example). It would bust the cache everytime you update your board, even when it's not necessary, but - updates don't happen all that often, and it removes all that noise in the templates (a variable does not need template updates - but of course you'd need these updates to put the variable in now...).

The only case where it causes problems is when you do an update that does not bump the version number, which shouldn't happen but MyBB has a bit of a history of doing.

If you want to take an extra step, stop using the version number altogether and instead make it some {$jsbump} which could be customizable in the ACP (same as cookie prefix), so admins can also trigger JS updates globally, in case they customize any of the javascript code.
Very good suggestion (Y)
(2017-11-15, 12:02 AM)frostschutz Wrote: [ -> ]It could simply be somefile.js?ver=${mybb->version} (not sure if that variable actually exists, just an example). It would bust the cache everytime you update your board, even when it's not necessary, but - updates don't happen all that often, and it removes all that noise in the templates (a variable does not need template updates - but of course you'd need these updates to put the variable in now...).

The only case where it causes problems is when you do an update that does not bump the version number, which shouldn't happen but MyBB has a bit of a history of doing.

If you want to take an extra step, stop using the version number altogether and instead make it some {$jsbump} which could be customizable in the ACP (same as cookie prefix), so admins can also trigger JS updates globally, in case they customize any of the javascript code.

That sounds like the best approach to me, for definite. Would save a bunch of issues we have with PRs missing version updates too. I've created an issue on GitHub for this: https://github.com/mybb/mybb/issues/2906
(2017-11-15, 10:22 PM)Euan T Wrote: [ -> ]
(2017-11-15, 12:02 AM)frostschutz Wrote: [ -> ]It could simply be somefile.js?ver=${mybb->version} (not sure if that variable actually exists, just an example). It would bust the cache everytime you update your board, even when it's not necessary, but - updates don't happen all that often, and it removes all that noise in the templates (a variable does not need template updates - but of course you'd need these updates to put the variable in now...).

The only case where it causes problems is when you do an update that does not bump the version number, which shouldn't happen but MyBB has a bit of a history of doing.

If you want to take an extra step, stop using the version number altogether and instead make it some {$jsbump} which could be customizable in the ACP (same as cookie prefix), so admins can also trigger JS updates globally, in case they customize any of the javascript code.

That sounds like the best approach to me, for definite. Would save a bunch of issues we have with PRs missing version updates too. I've created an issue on GitHub for this: https://github.com/mybb/mybb/issues/2906

Awesome, I hope something can be done for inline js as well.