S
S
sorry_i_noob2018-02-25 23:39:57
JavaScript
sorry_i_noob, 2018-02-25 23:39:57

Javascript how to deal with functions that are used on a particular page. Are they also written in one file? And how then to understand this file?

Hello.
I am writing code in Javascript. I've heard that the fewer calls to the server, the better. Moreover, the browser caches JS.
Therefore, you need to write javascript code in one file.
Here are my questions. If I write my JS code in a view (this is a .php page), won't the browser cache it?
And now I have functions that are used only on one page. And nowhere else. Should I also write them in one JS file? Maybe the user won't visit this page at all. And you have to download.
And if in one file, then how to understand this file later, it turns out to be huge.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Egor Zhivagin, 2018-02-26
@Krasnodar_etc

On questions:
1 - Write code in view - well, write, but why? No convenience, no asynchronous loading, no minification, no ES6.
2 - "code in one file" !== "write code in one file". You write the code in different files, how you arrange them more conveniently. Connect any faucet (Gulp, Webpack). With the assembler, you collect everything into one file, along the way you minify it, you can connect babel, ... , and tell the assembler where to put this one file.
I'm pretty sure you don't have enough code to paginate.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question