Skip to content

Src comparison does not work on relative URLs #1

@gavin310

Description

@gavin310

Thanks for this great code!

On line 79:
https://github.com/tech-marketing/video-srcset/blob/fea484de46d8a50efc60178dfeed9010a8cbd027/src/video-srcset.js#L79
There is the comparison to test if it should update the src or not. If you use relative URLs like in the main example (e.g. <video srcset="videos/mobile-video.mp4 768w, videos/tablet-video.mp4 1200w, videos/desktop-video.mp4 1920w"></video>) this comparison does not ever equate to true, because selectedSource will be the relative URL, but element.src will be the full URL including http://.

I fixed this by changing line 79 to:

if(element.src.slice(-selectedSource.length) !== selectedSource) {

Maybe there's a better way?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions