3 ms·
Not only hosting static assets yourself, it’s best to have them on your main (sub)domain. It saves a dns round trip when visiting site for the first time. It al
by samwillis 5y ago
Not only hosting static assets yourself, it’s best to have them on your main (sub)domain. It saves a dns round trip when visiting site for the first time. It also has the advantage with HTTP/2 being able to use that same initial connection for all assets on the page.
The old way of having your server rendered pages on your main domain and static assets on static.domain.com really should end. Less of an issue if your doing jamstack with no server side rendering or using something like Vercel.
This is also one of the advantages of using a combined waf/cdn such as CloudFlare. It allows you to have everything on the same domain while also having the use of waf and cdn capabilities. There is no need to have a subdomain to hold your static assets if you want to place it behind a cdn service. The only potentially problem is if your main hosting provider or tech stack makes having everything on one domain difficult.
I mostly work with Python on the sever and have found “whitenoise” a great way to achieve this.
Obviously it’s still easer to host any “dynamic” assets or user submitted assets on a subdomain. (There are good arguments that user submitted assets should be on another domain completely for belts and braces security)