Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing jquery code in external file and directory structure? [closed]

Can anyone can confirm the best idea for storing jquery code, initially i was inserting everything in the HEAD of a document but i am seeing more and more code being used across pages,

Is the best way to use include files .. with the extension .JS?

Anything else or better with respect to this?

What would be the best place to store my .js file if this is the case..

of the root i have

/css /scripts

etc ... /scripts is where my jquery files are... but should i be using the same for my .js files?

Anyone have some recommendation on directory structure?

like image 391
mark smith Avatar asked Feb 01 '26 17:02

mark smith


1 Answers

You should store as much code as you can in .js files, because that would allow the browser to download just once and re-use in all requests.

If you include your code directly in the HEAD section as plain text you're forcing that code to be downloaded in each request, slowing down the page transfer.

The directory where you store the files is up to you really... I use /css and /js, but /scripts is used as well in many ocassions.

like image 141
Seb Avatar answered Feb 04 '26 05:02

Seb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!