I have been working on a web page and would like to load multiple stylesheets in an external library.
Unfortunately, this library has many CSS files spread under the same folder.
The names are complicated and its such a pain to manually link it one by one.
As it
<link type="text/css" href="site/libraries/folder/highlight-areas.css"></link>
...
Is there a shortcut that loads all CSS files on the same page within the folder site/libraries/folder
I know how to do this with Ruby on Rails but that is another domain.
Is there a similar technique available on the client side?
Thanks in advance
Not as such, no. Javascript does not have access to server-side information at all. (And thank goodness!) However, if you wanted to, there is nothing to stop you from:
A. Grabbed the contents of all of the
.cssfiles inside ofsite/libraries/folderand served them up as one CSS file upon request.B. Sent your client-side script a list of all of the names of the
.cssfiles in the folder so it can load them when needed.A. Updates your
.js,.css, or.htmlfiles with the names of the.cssfiles you want to use.B. Concatenates all of your
.cssfiles into one file and deploys that to your server.Each of these approaches has strengths and weaknesses.
1Arequires processing time for every request (unless you cache the results, in which case you might want to consider just going for2B)1Bwill not work for clients with Javascript disabled. Both2Aand2Brequire that you always run your deploy scripts after you make an edit. So it’s really up to you.