Friday, July 1, 2022

[FIXED] Why is this code in my shopify theme file?

Issue

I noticed these few lines of code which all mentioned IE9 (which I'm assuming no one is using for the most part).

  <!--[if (gt IE 9)|!(IE)]><!--><script src="{{ 'lazysizes.min.js' | asset_url }}" async="async"></script><!--<![endif]-->
  <!--[if lte IE 9]><script src="{{ 'lazysizes.min.js' | asset_url }}"></script><![endif]-->

  {% if template.directory == 'customers' %}
    <!--[if (gt IE 9)|!(IE)]><!--><script src="{{ 'shopify_common.js' | shopify_asset_url }}" defer="defer"></script><!--<![endif]-->
    <!--[if lte IE 9]><script src="{{ 'shopify_common.js' | shopify_asset_url }}"></script><![endif]-->
  {% endif %}

  <!--[if (gt IE 9)|!(IE)]><!--><script src="{{ 'vendor.js' | asset_url }}"></script><!--<![endif]-->
  <!--[if lt IE 9]><script src="{{ 'vendor.js' | asset_url }}"></script><![endif]-->

Would this code be considered obsolete?


Solution

If you want to remove support for IE 9 or earlier version, you can remove the if let IE 9 part, but the other one

<!--[if (gt IE 9)|!(IE)]><!-->

This is for non-IE browsers and IE 9 above browsers, which I think you should keep.

The extra "<!" is ignored by non-IE browsers; it is also ignored by IE regardless of the condition because if false, everything within the conditional comment is ignored, and if true, the resulting tag <!--> is unrecognized and therefore ignored.

More readings on this https://en.wikipedia.org/wiki/Conditional_comment



Answered By - lastr2d2
Answer Checked By - Clifford M. (PHPFixing Volunteer)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.