Why does using asset_url in my code lead to 404 errors?

Why does using asset_url in my code lead to 404 errors?

CélinePo
Tourist
7 0 1

Hi,

 

I can't find the best way for my problem.

I have this code in my theme : 

 

{% if pageUrl contains '?page=' %}
{% assign special_canonical = true %}
{% assign canonicalPageArray = pageUrl | split: "=" %}
{% assign canonicalPageNumber = canonicalPageArray | last %}
{% endif %}
{%- endfor -%}

{% if special_canonical %}
<link rel="canonical" href="{{ canonical_url }}?page={{ canonicalPageNumber }}" />
{% elsif template contains 'collection' and current_tags %}
<meta name="robots" content="noindex" />
<link rel="canonical" href="{{ shop.url }}{{ collection.url }}" />
{% else %}
<link rel="canonical" href="{{ canonical_url }}" />
{% endif %}

 

I tried to use "asset_url" as shopify's IDE ask so I changed for : 

 

{% if special_canonical %}
<link rel="canonical" href="{{ canonical_url | asset_url }}?page={{ canonicalPageNumber }}" />
{% elsif template contains 'collection' and current_tags %}
<meta name="robots" content="noindex" />
<link rel="canonical" href="{{ shop.url | asset_url }}{{ collection.url }}" />
{% else %}
<link rel="canonical" href="{{ canonical_url | asset_url }}" />
{% endif %}

 

My webscore increased by 15% but I avec full 404 errors on sitechecker...

Thoses errors concerns url not used with CDN like but it seems indexed by Google: 

https://potiron.com/cdn/shop/t/93/assets/blogs/magazine-potiron-paris/tagged/comment-bien-agencer-un...

linked to url not used like : 

https://potiron.com/cdn/shop/t/93/assets/collections/soldes?64780?page=6&_cf_orig_host=potiron2021.m...

 

Why asset_url seems wrong ?

What is preferable ?

Can someone explain to me what is going on ?

 

Thanks a lot

 

Replies 3 (3)

Jason
Shopify Partner
11207 226 2319

The asset_url filter is for generating a link to an asset (so an image for example). You should expect a CDN link to be returned. It doesn't make sense to use it like that. 

What is the reason you had for doing that?

★ I jump on these forums in my free time to help and share some insights. Not looking to be hired, and not looking for work. http://freakdesign.com.au ★
CélinePo
Tourist
7 0 1

Thank you Jason ! 

I did that because of error messages in shopify template like :

ClinePo_0-1693399658065.png

I try to find what are problem with canonical url. Sitechecker always find issues

 

Odell_Creations
Tourist
10 0 7

I am wondering this myself.  The editor throws that code for me too.  I wondered if part of the code was deleted accidentally or something but now I see it is like that with yours too. 

https://odellcreations.com
odellcreations@odellcreations.com