Lazysizes: data-srcset with filenames containing spaces breaks parsing

Created on 5 Feb 2015  路  7Comments  路  Source: aFarkas/lazysizes

When using filenames that contain whitespace (which may easily occur when customers upload files with unexpected filenames) parsing of data-srcset breaks.

E.g. data-srcset="http://localhost/uploads/images/test (1).jpg 320w, http://localhost/uploads/images/test (1).jpg 480w"

-> 'Failed parsing 'srcset' attribute value since it has an unknown descriptor.'

Most helpful comment

Protip if anybody else lands here, make sure your srcsets have commas :)

All 7 comments

Well.... One second after filing the bug I realized that this seems to be an issue with chrome only.. The exception is not raised from lazysizes but from chrome.. So I guess you are not able to do something about it. :)

And I should URL-encode the URLs - so closing this issue...

Got the same error in console. Annoying.
What do you mean by "URL-encode the URLs" and how can I avoid chrome showing this for every image loaded?

You can fix this by not using white spaces in your URL. These characters are not allowed

hmmm. Yes. But I scripted my img-elements with:

    'data-bgset': `
      ${filename}-100.jpg 100w,
      ${filename}-500.jpg 500w,
      ${filename}-900.jpg 900w,
      ${filename}-1100.jpg 1100w,
      ${filename}-1300.jpg 1300w,
      ${filename}-2000.jpg 2000w
    `

so whitespaces are needed for the different sizes?

The output of ${filename} should not contain any whitespace. This is what aFarkas meant.

Protip if anybody else lands here, make sure your srcsets have commas :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

maximelebreton picture maximelebreton  路  4Comments

jpw123 picture jpw123  路  6Comments

zenderol picture zenderol  路  5Comments

ymantijunk picture ymantijunk  路  5Comments

virginiarcruz picture virginiarcruz  路  3Comments