Should I use absolute paths for CSS or JS resources in <link and <script tags?

Is there any reason?

Some SEO optimization say fix it, should I do it for any reason?

I do not know why, if everything is working fine?

<link rel="stylesheet" href="/css/main_rtl.css?v=5e6e47e9">
<script src="/lib/js/frameworks.min.js?v=5e6e47e9"></script>


<link rel="stylesheet" href="https://sample.com/css/main_rtl.css?v=5e6e47e9">
<script src="https://example.com/lib/js/frameworks.min.js?v=5e6e47e9"></script>

Is there any SEO-related point?

Shorter version is smaller HTML at least.

  • each page has canonical
  • domain only serve https version(http redirect to https)
  • 1
    There is no difference
    – John Conde
    Oct 7, 2019 at 19:06
  • 3
    "Some SEO optimization say fix it" Which resource say what exactly? It would be better to explicitly cite the sources/references on which your question is built. Also about "Shorter version is smaller HTML at least." this shouldn't make a lot of differences today. Also the relative version is not without merits: if you change the hostname one day you have less changes to do. Oct 7, 2019 at 19:24
  • @PatrickMevzek my friend as person suggest it
    – sweb
    Oct 13, 2019 at 12:09

1 Answer 1


If your website is available on both http and https I definitely recommend using relative path and not absolute. Otherwise I cant really see any specific difference.

The SEO optimization services might recommend you to use absolute paths because it could in theory create some issues for them if you use relative path, but I would ignore that myself because I don't think it matter much for Google and other large indexers.

  • 3
    Personally I'd advice to use //example.com/assets/file.js to avoid issues between dev/staging/prod env. Also with many routes and eg emails the relatives paths are becoming a problem - it's easier to point an absolute path. Another point is that most frameworks provide you with param that's relative, but print out the actual absolute path.
    – versedi
    Oct 7, 2019 at 21:35
  • 1
    @versedi Sounds like an answer! You make some excellent points. Cheers!
    – closetnoc
    Oct 7, 2019 at 21:51
  • website serve only on https, http redirect to https for all requests
    – sweb
    Oct 8, 2019 at 5:38
  • @versedi good point
    – Don King
    Oct 13, 2019 at 16:22
  • @versedi I disagree. There are two problem with using fully qualified paths. (1) You cant test it on a local server. With relative paths, I can test the whole thing on my development machine. (2) You cant shift the code to another domain, without making changes. I am working on 3 websites simultaneously and its really really helpful to be able to copy and paste the references. Finally, I could be wrong, but I suspect that having relative paths is faster to evaluate. Jan 14 at 21:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.