1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Proper way to call an image

Discussion in 'Programming' started by Matthew Sayle, Jul 6, 2016.

  1. #1
    Hello!

    From a page speed, SEO and usability standpoint - is there any real difference between:

    http://example.com/images/image.png
    vs
    /images/image.png

    I get it, while the former is quicker and easier to write. However, with Wordpress - would it be worth my time to go in and remove the domain across the board, leaving only the directory path?

    Does one provide an advantage over the other?

    Thanks for all of your insight!
     
    Solved! View solution.
    Matthew Sayle, Jul 6, 2016 IP
  2. #2
    For page-speed purposes, and/or SEO, it shouldn't matter. However, if you consider portability, hardcoded full URLs is bad. At least, if you're gonna use full URLs, you need some sort of pulling of the current domain, so that you can port it to whatever domain you're using.

    Also, the problem of http vs https - relative urls doesn't care about what protocol you're using, and generally the relative urls are a better option overall.
     
    PoPSiCLe, Jul 6, 2016 IP
    Matthew Sayle likes this.
  3. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #3
    That would be my vote. Having the actual images relative /images/x.jpg but the actual URLs absolute: http://google.com/images/x.jpg via a configurable param. This will make it easy to switch your assets to CDN if you ever need to.

    That can easily be solved by using protocol-less urls: //google.com/images/x.jpg

    IMO relative urls storage wise, but when serving have the absolute urls (unless you know you will never need it).
     
    ThePHPMaster, Jul 6, 2016 IP
    Matthew Sayle likes this.
  4. Online ™

    Online ™ Greenhorn

    Messages:
    2
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    5
    #4
    Absolute paths (URLs) should be used only when requesting external resources. As simple as that.
     
    Online ™, Jul 6, 2016 IP
    Matthew Sayle likes this.
  5. Matthew Sayle

    Matthew Sayle Prominent Member

    Messages:
    3,325
    Likes Received:
    464
    Best Answers:
    1
    Trophy Points:
    385
    #5
    Thanks guys!

    Exactly what I was looking for.
     
    Matthew Sayle, Jul 6, 2016 IP