S
S
stanlee2015-09-23 17:04:39
css
stanlee, 2015-09-23 17:04:39

How to load different sets of libraries on different pages?

There are pages where jquery libraries like colorbox selectbox rado and others are used. The
question is - is it right to drive them all into the assembly together or is there another solution?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dmitry Novikov, 2015-09-23
@dmitriy_novikov

usually yes, all libraries are loaded together in the head or at the end of the site template.
of course, you can pull them depending on the page, but such code is more difficult to maintain, and the difference in loading speed is usually very small.

G
Gregory, 2015-09-23
@grigruss

It all depends on the engine. For example, if PHP is used, then before sending the page to the browser, you can set a condition like:

$head="<!DOCTYPE html><html><head><meta charset=\"utf-8\">
if(strpos($html,"$(")!==FALSE){ // сочетание $( или jQuery( всегда есть в кодах jQuery
    $head.="<script type=\"text/javascript\" src=\"js/jquery-2.1.4.min.js\"></script>";
}
$head.="</head>"; // и так далее

V
Vitaly Inchin ☢, 2015-09-23
@In4in

I don't see much point if caching is enabled for js files.
Sooner or later, the visitor will have to load the script on some page of your site, so why not do it the first time they visit any of the pages? All at once, but once.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question