Jump to content

Welcome, Guest!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

  • 0
Pierrox15

Overriding core js on front

Question

Hello,

I'm writing theme and some Tb core js file are not needed.

I know how to override js from module, But How can I  disable some js from the core properly in my thème?

I have made a conditionnal preg_match in the header.tpl for test, but  when I set the concat js option in Backoffice this is ignored

{foreach from=$js_files item=js_uri}
  {if !preg_match("/(ui.position|jquery.autocomplete|jquery.scrollTo|jquery.serialScroll|bxslider|ui.position|blocksearch)/", $js_uri)}
   <script type="text/javascript" src="{$js_uri|escape:'html':'UTF-8'}"></script>
  {/if}
 {/foreach}

Share this post


Link to post
Share on other sites

6 answers to this question

Recommended Posts

  • 0
13 minutes ago, Pierrox15 said:

Hello,

I'm writing theme and some Tb core js file are not needed.

I know how to override js from module, But How can I  disable some js from the core properly in my thème?

I have made a conditionnal preg_match in the header.tpl for test, but  when I set the concat js option in Backoffice this is ignored


{foreach from=$js_files item=js_uri}
  {if !preg_match("/(ui.position|jquery.autocomplete|jquery.scrollTo|jquery.serialScroll|bxslider|ui.position|blocksearch)/", $js_uri)}
   <script type="text/javascript" src="{$js_uri|escape:'html':'UTF-8'}"></script>
  {/if}
 {/foreach}

That's not theme's responsibility. You don't know why these js files are requested to be included in the page -- there might be some third party module that need some of these libraries and it *asked* core to include it. Theme's responsibility is to include everything that was requested. Otherwise you break stuff. 

I know it's stupid, and it leads to bloated themes with trillions of unused js libs, but that that how it is. 

Share this post


Link to post
Share on other sites
  • 0

Ok, thx.

Another question about "Smart" cache for CSS

the compressed css filename is different on home / category / product. Is it a bug?  does it desserve a bug report?

Normally at the first load, all my CSS will be ready for all the website ; I think.

Share this post


Link to post
Share on other sites
  • 0

I don't think that's a bug. Every page has its own set of css/js dependencies -- there are modules that includes some css / javascript on homepage only, or on product page only. Core collects all these assets and creates a bundle from it. These bundles are different, since they consist of different content.

Of course, this could (and should) be optimized. For example, core could calculate intersection of these bundles, and generate some common.js / common.css files. Every page would then serve this common.js + page-specific.js files. There would be more resources on the page, but overall performance would probably increase - common assets would be cached by browsers. 

You can file this as an enhancement request

Share this post


Link to post
Share on other sites
  • 0
Posted (edited)
19 hours ago, datakick said:

Of course, this could (and should) be optimized. For example, core could calculate intersection of these bundles, and generate some common.js / common.css files. Every page would then serve this common.js + page-specific.js files. There would be more resources on the page, but overall performance would probably increase - common assets would be cached by browsers. 

You can file this as an enhancement request

I think it will be more simple for optimize, calculate intersection is a good idea but in practice it feel a bit complicated for something simple. for example my compressed CSS have only 1ko variation between product / category / home. The files have at 99% the same code.

So I have reported here: https://github.com/thirtybees/thirtybees/issues/1032

thx

Edited by Pierrox15
Forget report

Share this post


Link to post
Share on other sites
  • 0
6 minutes ago, Pierrox15 said:

I think it will be more simple for optimize, calculate intersection is a good idea but in practice it feel a bit complicated for something simple. for example my compressed CSS have only 1ko variation between product / category / home. The files have at 99% the same code.

It's not that simple. This extra 1k code can have huge impact. There can be some initialization script that expects to run on specific page only. If we executed this script on different page, it might produce a lot of errors. These errors or exception can prevent other js scripts to initialize correctly, and... we have not working page.

There's no shortcut here. The page must contain all the javascript that's requested. Nothing less, nothing more. So, the only way to optimize this is indeed to split it into common + specific javascript chunks.   

Share this post


Link to post
Share on other sites
  • 0
7 minutes ago, datakick said:

and... we have not working page.

Ok I see. For me a classic PHP HTML app will be totally accessible & usable without JS.  JS is the icing on the cake and come at the end to improve UX. So that how it is.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...