javascript - Do JS event listeners cost more than an additional HTTP request? -


i have heard best condense javascript 1 file reduce number of http requests application makes. however, hold true if make use of event listeners each specific 1 page of site?

for example, have 3 different pages make ajax requests load random picture server. first page listens button click, second page listens mouseover, , third page listens change in value of select field. make sense have 1 giant js file contains dom-manipulation logic, event listeners? or better define necessary dom-manipulation logic in 1 file , have 1 small js file each page page-specific event listeners page.

tl;dr: event listeners elements not exist on page cost more in performance http requests additional js file?

reduction of number of requests 1 reason consolidating javascript files one.

the other reason this: javascript file can, after browser has downloaded once, retrieved browser cache when subsequent pages use it. fewer files means more streamlined caching.

the cost of little javascript minimal. jquery style listeners attached no dom elements cost while onload method trying attach them.

so easy way. when have tens of millions of page views per hour time kind of optimizations question mentions.

there's no harm in inlining small amounts, or medium amounts, of javascript if it's easier. view source on search engine's front door page example.


Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -