Run javascript function on AJAX calls to a specific page

Asked

Viewed 357 times

0

I have a site in Laravel where the content is dynamically loaded with AJAX, IE, in each call Laravel returns only the view of the part I need, in a certain page I need to initialize a jQuery plugin that I only use on this page. If I boot this plugin in all calls will work, but I will end up creating an unnecessary overhead. What is the best method of passing this JS function call when I call for such a page happen?

1 answer

1

Using or implementing some Lazy load library, which loads the scripts on demand.

How about something like:

myLib.load(['jquery', 'jquery-ui', 'fancybox'], function(){
    // Isso aqui só vai rodar quando as 3 dependências forem carregadas
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.