Style sheets (js,css) in subdomain or in a folder within the application?

Asked

Viewed 142 times

0

I’m having a question. I think someone’s been through it some day too.

I always loaded my styles inside a folder in my application:

Ex: http://meudominio.com.br/assets/css - ou js e etc

Observing many other developers' source code, 50% use subdomain:

Ex: http://assets.meudominio.com.br/css - ou js e etc

Having some kind of subdomain for styles increases performance relative to page loading?

What is the best practice for performance?

Remember that I use PHP with Codeigniter in most of my applications. And I have a cloud server with Cpanel. (If this information helps..)

2 answers

2


Subdomain is the best option to put your static files.

Because when the user accesses it will download in parallel the files of the subdomain. Which will make it quicker if compared to everything being on the same domain, where you will send a request, wait for the return, then start another request.

Using CDN for your files is also a good option, for example jquery, if you use jquery https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.js and the user has already accessed some site, where use this CDN too, he will already have this file in the browser cache, and will not download again, which will make the access to your site faster.

1

Probably for reasons of cache and bandwidth saving.

Because if you access:

  1. http://site.com
  2. http://site.com

When accessing #1 it will load the js, css files. If you access #2 it will try to load again as it will find that it is a different file.

Already using only a sub-domain doesn’t matter which address you are on if it has already loaded once it won’t try to download again and will take advantage of the cache. That’s why people use CDN, because several sites share the same address for a certain file ex: jQuery.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.