Have your say in Community Polls: What was/is your greatest motivation to start your own business?

Theme.liquid java script

Solved

Theme.liquid java script

learningdesign
Shopify Partner
205 1 24

In my Assets Folder

i have created  a file
application.js.liquid

and then transfer all codes  from .js files on assets folder to my application file which i have created

then in  theme.liquid  file i have delete all .js  scripts   and paste  this code in the last of theme.liquid

</body> this code <script src="{{ 'application.js' | asset_url }}" async defer> </script>

but when i do this webiste few section got broke beccasue of these three codes

{{ 'slideshow.js' | asset_url | script_tag }}
{{ 'animations.min.js' | asset_url | script_tag }}

{{ 'vendor.min.js' | asset_url | script_tag }}

when i delte this website got broke when i leave this website is ok  how to solve this problem please i am doing all this to increase my speed in getmetrix

learningdesign_0-1724385798420.png

 



Accepted Solutions (3)
Huptech-Web
Shopify Partner
1010 204 217

This is an accepted solution.

Hi @learningdesign, As you have added all the JS in a single file it might cause an issue because of dependency. As you know apart from theme.liquid many JS are used in sections and snippets which may create a conflict. To resolve this issue you need to break down your Javascript code. Add the JS file code one by one to your file and check if any error occurs or your theme breaks. This way you will know which file or code is creating the conflict.

If you found this response helpful, please do like and accept the solution. Thanks!
Need support with Customizing your Shopify store?
Feel free to contact me at info@huptechweb.com or Visit our website Huptech Web.
Instant Shortcode Builder: Integrate customizable UI features anywhere in your store - No coding knowledge required

View solution in original post

Huptech-Web
Shopify Partner
1010 204 217

This is an accepted solution.

Okay, I have checked these files are called twice on your store! That can also create a conflict in your code. If you add them to your code then remove them from the theme.liquid so they don't render twice on the site.

If you found this response helpful, please do like and accept the solution. Thanks!
Need support with Customizing your Shopify store?
Feel free to contact me at info@huptechweb.com or Visit our website Huptech Web.
Instant Shortcode Builder: Integrate customizable UI features anywhere in your store - No coding knowledge required

View solution in original post

Huptech-Web
Shopify Partner
1010 204 217

This is an accepted solution.

If removing these codes from theme.liquid breaks your website then leave them as they are and remove its code from your application.js.liquid.

If you found this response helpful, please do like and accept the solution. Thanks!
Need support with Customizing your Shopify store?
Feel free to contact me at info@huptechweb.com or Visit our website Huptech Web.
Instant Shortcode Builder: Integrate customizable UI features anywhere in your store - No coding knowledge required

View solution in original post

Replies 12 (12)

Huptech-Web
Shopify Partner
1010 204 217

Hi @learningdesign, You should use "async" or "defer" in the script tag do not use both. Replace the below script with your code. Also, Check the sequence of the code. Add the code to your file in the same sequence.

<script src="{{ 'application.js' | asset_url }}" defer> </script>

 

If this does not work please provide me the storefront URL.

If you found this response helpful, please do like and accept the solution. Thanks!
Need support with Customizing your Shopify store?
Feel free to contact me at info@huptechweb.com or Visit our website Huptech Web.
Instant Shortcode Builder: Integrate customizable UI features anywhere in your store - No coding knowledge required
learningdesign
Shopify Partner
205 1 24

yes the sequence is correct with your code also it did not work

Huptech-Web
Shopify Partner
1010 204 217

Hi @learningdesign, I checked that your JS is called at the end. Can you share the screenshot where you have added your code exactly in the theme.liquid?

If you found this response helpful, please do like and accept the solution. Thanks!
Need support with Customizing your Shopify store?
Feel free to contact me at info@huptechweb.com or Visit our website Huptech Web.
Instant Shortcode Builder: Integrate customizable UI features anywhere in your store - No coding knowledge required
learningdesign
Shopify Partner
205 1 24

Screen shot with full code 

learningdesign_0-1724412001316.png

 

<!doctype html>
{%- capture dir -%}
{%- case request.locale.iso_code -%}
  {%- when 'ae' or 'ar' or 'arc' or 'bcc' or 'bqi' or 'ckb' or 'dv' or 'fa' or 'glk' or 'ha' or 'he' or 'kwh' or 'ks' or 'ku' or 'mzn' or 'nqo' or 'pnb' or 'ps' or 'sd' or 'ug' or 'ur' or 'yi' -%}
    rtl
  {%- else -%}
    ltr
{%- endcase -%}
{%- endcapture -%}
<html class="no-js" lang="{{ request.locale.iso_code }}" dir="{{ dir }}">
<head>{% render 'thunder-injects' %}
 
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=5, viewport-fit=cover">
<meta name="theme-color" content="{{ settings.color_body_bg }}">
<link rel="canonical" href="{{ canonical_url }}">
<link rel="preconnect" href="https://cdn.shopify.com" crossorigin>
{% render 'head-preload' %}
 
{% if settings.favicon != blank -%}
<link rel="icon" type="image/png" href="{{ settings.favicon | image_url: width: 32, height: 32 }}">
{%- endif %}
 
<title>
{{ page_title }}{% if current_tags %}{% assign meta_tags = current_tags | join: ', ' %} &ndash; {{ 'general.meta.tags' | t: tags: meta_tags }}{% endif %}{% if current_page != 1 %} &ndash; {{ 'general.meta.page' | t: page: current_page }}{% endif %}{% unless page_title contains shop.name %} &ndash; {{ shop.name }}{% endunless %}
</title>
 
{% if page_description %}
<meta name="description" content="{{ page_description | escape }}">
{% endif %}
 
{%- unless settings.heading_font.system? and settings.body_font.system? -%}
<link rel="preconnect" href="https://fonts.shopifycdn.com" crossorigin>
{%- endunless -%}
 
{% render 'social-meta-tags' %}
 
{{ 'app.css' | asset_url | stylesheet_tag }}
{{ 'product-grid.css' | asset_url | stylesheet_tag }}
 
{% render 'head-variables' %}
 
<script>
window.theme = window.theme || {};
theme = {
settings: {
money_with_currency_format: {{- shop.money_format | json -}},
cart_drawer: {{- settings.cart_drawer -}}
},
routes: {
root_url: '{{ routes.root_url }}',
cart_url: '{{ routes.cart_url }}',
cart_add_url: '{{ routes.cart_add_url }}',
search_url: '{{ routes.search_url }}',
cart_change_url: '{{ routes.cart_change_url }}',
cart_update_url: '{{ routes.cart_update_url }}',
predictive_search_url: '{{ routes.predictive_search_url }}',
},
variantStrings: {
        addToCart: `{{ 'products.product.add_to_cart' | t }}`,
        soldOut: `{{ 'products.product.sold_out' | t }}`,
        unavailable: `{{ 'products.product.unavailable' | t }}`,
      }, 
          
strings: {
requiresTerms: `{{ 'sections.cart.terms_confirm' | t }}`,
}
};
</script>
{%- if tinyscript -%}{{ content_for_header }}{%- else -%}{% render 'tiny-script-control' %}{%- endif -%} <!-- Header hook for plugins -->
 
<script>document.documentElement.className = document.documentElement.className.replace('no-js', 'js');</script>
{% include 'hulk_po_vd' %}</head>
<body class="animations-{{ settings.animations }} button-uppercase-{{ settings.button_uppercase }} navigation-uppercase-{{ settings.navigation_uppercase }} product-card-spacing-{{ settings.product_card_spacing }} article-card-spacing-{{ settings.article_card_spacing }} {% if customer %} customer-logged-in{% endif %} template-{{ template | replace: '.', ' ' | truncatewords: 1, '' | handle }} template-{{ template | replace: '.', '-' | handle }}">
<a class="screen-reader-shortcut" href="#main-content">{{ 'accessibility.skip_to_text' | t }}</a>
<div id="wrapper">
<div class="header--sticky"></div>
{% sections 'header-group' %}
<div role="main" id="main-content">
{{ content_for_layout }}
</div>
{% sections 'footer-group' %}
{% render 'cart-drawer' %}
{% render 'product-drawer' %}
{% render 'search-drawer' %}
<div class="click-capture"></div>
<div class="click-capture--product"></div>
</div>
 
{{ 'vendor.min.js' | asset_url | script_tag }}
{% if settings.animations %}
{{ 'animations.min.js' | asset_url | script_tag }}
<script>
gsap.defaults({
ease: Power4.easeOut
});
gsap.config({
    nullTargetWarn: false
  });
gsap.registerPlugin(ScrollTrigger, DrawSVGPlugin);
</script>
      
{% endif %}
 
{{ 'slideshow.js' | asset_url | script_tag }}
 
 
{%- if settings.free_shipping -%}
 
{%- endif -%}
{%- if request.design_mode -%}
 
{%- endif -%}
{% render 'back-to-top' %}
 
{% render 'thunder-preload' %}
  <script src="{{ 'application.js' | asset_url }}" defer> </script> 
</body>
</html>

 

learningdesign
Shopify Partner
205 1 24
<!doctype html>
{%- capture dir -%}
{%- case request.locale.iso_code -%}
  {%- when 'ae' or 'ar' or 'arc' or 'bcc' or 'bqi' or 'ckb' or 'dv' or 'fa' or 'glk' or 'ha' or 'he' or 'kwh' or 'ks' or 'ku' or 'mzn' or 'nqo' or 'pnb' or 'ps' or 'sd' or 'ug' or 'ur' or 'yi' -%}
    rtl
  {%- else -%}
    ltr
{%- endcase -%}
{%- endcapture -%}
<html class="no-js" lang="{{ request.locale.iso_code }}" dir="{{ dir }}">
<head>{% render 'thunder-injects' %}
 
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=5, viewport-fit=cover">
<meta name="theme-color" content="{{ settings.color_body_bg }}">
<link rel="canonical" href="{{ canonical_url }}">
<link rel="preconnect" href="https://cdn.shopify.com" crossorigin>
{% render 'head-preload' %}
 
{% if settings.favicon != blank -%}
<link rel="icon" type="image/png" href="{{ settings.favicon | image_url: width: 32, height: 32 }}">
{%- endif %}
 
<title>
{{ page_title }}{% if current_tags %}{% assign meta_tags = current_tags | join: ', ' %} &ndash; {{ 'general.meta.tags' | t: tags: meta_tags }}{% endif %}{% if current_page != 1 %} &ndash; {{ 'general.meta.page' | t: page: current_page }}{% endif %}{% unless page_title contains shop.name %} &ndash; {{ shop.name }}{% endunless %}
</title>
 
{% if page_description %}
<meta name="description" content="{{ page_description | escape }}">
{% endif %}
 
{%- unless settings.heading_font.system? and settings.body_font.system? -%}
<link rel="preconnect" href="https://fonts.shopifycdn.com" crossorigin>
{%- endunless -%}
 
{% render 'social-meta-tags' %}
 
{{ 'app.css' | asset_url | stylesheet_tag }}
{{ 'product-grid.css' | asset_url | stylesheet_tag }}
 
{% render 'head-variables' %}
 
<script>
window.theme = window.theme || {};
theme = {
settings: {
money_with_currency_format: {{- shop.money_format | json -}},
cart_drawer: {{- settings.cart_drawer -}}
},
routes: {
root_url: '{{ routes.root_url }}',
cart_url: '{{ routes.cart_url }}',
cart_add_url: '{{ routes.cart_add_url }}',
search_url: '{{ routes.search_url }}',
cart_change_url: '{{ routes.cart_change_url }}',
cart_update_url: '{{ routes.cart_update_url }}',
predictive_search_url: '{{ routes.predictive_search_url }}',
},
variantStrings: {
        addToCart: `{{ 'products.product.add_to_cart' | t }}`,
        soldOut: `{{ 'products.product.sold_out' | t }}`,
        unavailable: `{{ 'products.product.unavailable' | t }}`,
      }, 
          
strings: {
requiresTerms: `{{ 'sections.cart.terms_confirm' | t }}`,
}
};
</script>
{%- if tinyscript -%}{{ content_for_header }}{%- else -%}{% render 'tiny-script-control' %}{%- endif -%} <!-- Header hook for plugins -->
 
<script>document.documentElement.className = document.documentElement.className.replace('no-js', 'js');</script>
{% include 'hulk_po_vd' %}</head>
<body class="animations-{{ settings.animations }} button-uppercase-{{ settings.button_uppercase }} navigation-uppercase-{{ settings.navigation_uppercase }} product-card-spacing-{{ settings.product_card_spacing }} article-card-spacing-{{ settings.article_card_spacing }} {% if customer %} customer-logged-in{% endif %} template-{{ template | replace: '.', ' ' | truncatewords: 1, '' | handle }} template-{{ template | replace: '.', '-' | handle }}">
<a class="screen-reader-shortcut" href="#main-content">{{ 'accessibility.skip_to_text' | t }}</a>
<div id="wrapper">
<div class="header--sticky"></div>
{% sections 'header-group' %}
<div role="main" id="main-content">
{{ content_for_layout }}
</div>
{% sections 'footer-group' %}
{% render 'cart-drawer' %}
{% render 'product-drawer' %}
{% render 'search-drawer' %}
<div class="click-capture"></div>
<div class="click-capture--product"></div>
</div>
 
{{ 'vendor.min.js' | asset_url | script_tag }}
{% if settings.animations %}
{{ 'animations.min.js' | asset_url | script_tag }}
<script>
gsap.defaults({
ease: Power4.easeOut
});
gsap.config({
    nullTargetWarn: false
  });
gsap.registerPlugin(ScrollTrigger, DrawSVGPlugin);
</script>
      
{% endif %}
{{ 'product.js' | asset_url | script_tag }}
{{ 'slideshow.js' | asset_url | script_tag }}
{{ 'app.js' | asset_url | script_tag }}
<script type="module" src="{{ 'scroll-shadow.js' | asset_url }}" defer="defer"></script>
<script src="{{ 'predictive-search.js' | asset_url }}" defer="defer"></script>
{%- if settings.free_shipping -%}
{{ 'free-shipping.js' | asset_url | script_tag }}
{{ 'free-shipping.css' | asset_url | stylesheet_tag }}
{%- endif -%}
{%- if request.design_mode -%}
{{ 'theme-editor.js' | asset_url | script_tag }}
{%- endif -%}
{% render 'back-to-top' %}
{{'tiny-img-link-preloader.js' | asset_url | script_tag }}
{% render 'thunder-preload' %}
</body>
</html>


this is my theme.liquid code and my sequence is

Vendor
animation
product
slideshow
app
scroll-shadow
predictive-search
freeshipping
theme-editor
tiny-img-link-preloader


please check what i am doing wrong here 








 

Huptech-Web
Shopify Partner
1010 204 217

This is an accepted solution.

Hi @learningdesign, As you have added all the JS in a single file it might cause an issue because of dependency. As you know apart from theme.liquid many JS are used in sections and snippets which may create a conflict. To resolve this issue you need to break down your Javascript code. Add the JS file code one by one to your file and check if any error occurs or your theme breaks. This way you will know which file or code is creating the conflict.

If you found this response helpful, please do like and accept the solution. Thanks!
Need support with Customizing your Shopify store?
Feel free to contact me at info@huptechweb.com or Visit our website Huptech Web.
Instant Shortcode Builder: Integrate customizable UI features anywhere in your store - No coding knowledge required
learningdesign
Shopify Partner
205 1 24

I have already did that these 3 codes are breaking website

{{ 'vendor.min.js' | asset_url | script_tag }}
{{ 'animations.min.js' | asset_url | script_tag }}
{{ 'slideshow.js' | asset_url | script_tag }}

Huptech-Web
Shopify Partner
1010 204 217

This is an accepted solution.

Okay, I have checked these files are called twice on your store! That can also create a conflict in your code. If you add them to your code then remove them from the theme.liquid so they don't render twice on the site.

If you found this response helpful, please do like and accept the solution. Thanks!
Need support with Customizing your Shopify store?
Feel free to contact me at info@huptechweb.com or Visit our website Huptech Web.
Instant Shortcode Builder: Integrate customizable UI features anywhere in your store - No coding knowledge required
learningdesign
Shopify Partner
205 1 24

if i remove these 3 scripts from theme. liquid  my website got broke 

you mean i need to delete it from the application.js.liquid  file where i copy all code ?

Huptech-Web
Shopify Partner
1010 204 217

This is an accepted solution.

If removing these codes from theme.liquid breaks your website then leave them as they are and remove its code from your application.js.liquid.

If you found this response helpful, please do like and accept the solution. Thanks!
Need support with Customizing your Shopify store?
Feel free to contact me at info@huptechweb.com or Visit our website Huptech Web.
Instant Shortcode Builder: Integrate customizable UI features anywhere in your store - No coding knowledge required
learningdesign
Shopify Partner
205 1 24

Can you help me in any one of this error which will make my website speed little better becasue this minify  js   did not have any effect on my website

learningdesign_0-1724417394809.png

 

Huptech-Web
Shopify Partner
1010 204 217

Hi @learningdesign , You can fix the speed issue by fixing the large content paint "Largest Contentful Paint", "Avoid Large layout Shifts", and "Reduce Javascript Execution time" issues. It will help you improve your website speed.

If you found this response helpful, please do like and accept the solution. Thanks!
Need support with Customizing your Shopify store?
Feel free to contact me at info@huptechweb.com or Visit our website Huptech Web.
Instant Shortcode Builder: Integrate customizable UI features anywhere in your store - No coding knowledge required