Welcome to WebmasterWorld Guest from 54.166.152.121

Forum Moderators: open

Message Too Old, No Replies

Remote Scripts - best practice for speed

Is it better to link to a remote script, or embed it directly on your site?

     
1:36 am on Dec 18, 2013 (gmt 0)



So, I use a script like this on my website:

<script type="text/javascript" src="http://scriptsource.com/whatever-min.js"></script>


From a performance/speed perspective, is it better to pull a script from a remote source like that, or embed the whole script directly on my site?
8:54 am on Dec 18, 2013 (gmt 0)

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



it's a tradeoff.
if you put a script in your document it saves an extra request for a server resource.
however an external script can be cached by the browser and reused for later visits or on other pages.
an external script also reduces the size of the html document.
in some cases, serving an external script from a separate domain, especially if it's on a content delivery network, can help performance.
if the script is served from a cookieless domain that can also improve performance.
9:10 am on Dec 18, 2013 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



in some cases, serving an external script from a separate domain, especially if it's on a content delivery network, can help performance.

Can the connection be so much faster that it outweighs the extra time involved in looking up a whole other domain?
4:06 pm on Dec 18, 2013 (gmt 0)

WebmasterWorld Senior Member drdoc is a WebmasterWorld Top Contributor of All Time 10+ Year Member



No, first connections anywhere are always made at a loss in performance. But, assuming you are not using some fringe library, chances are that people have common domains cached in their browser/router/DNS.
4:09 pm on Dec 18, 2013 (gmt 0)

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



your browser limits the number of simultaneous connections to a server, so the extra DNS lookup is yet another tradeoff vs the total number of connections required (aka "in some cases")

the CDN tradeoff is more DNS lookups vs lower latency and perhaps more cached resources.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month