jquery slim что это

На CDNJS размещен пакет jquery.slim. Он имеет меньший размер. Каковы основные отличия от оригинала? Беглый взгляд на код не дал ответа, и на jquery.com я не нашел никаких ссылок о slim упаковке.

Итак, каковы различия между jquery.js и jquery.slim.js?

6 ответов

Глядя на код, я обнаружил следующие различия между jquery.js и jquery.slim.js:

В jquery.slim.js удалены следующие функции кода:

  1. jQuery.fn.extend
  2. jquery.fn.load
  3. jquery.each // Прикрепите набор функций для обработки общих событий AJAX
  4. jQuery.expr.filters.animated
  5. настройки ajax, такие как jQuery.ajaxSettings.xhr, jQuery.ajaxPrefilter, jQuery.ajaxSetup, jQuery.ajaxPrefilter, jQuery.ajaxTransport, jQuery.ajaxSetup
  6. XML-разбор, как jQuery.parseXML,
  7. анимационные эффекты, такие как jQuery.easing, jQuery.Animation, jQuery.speed

Наряду с обычной версией jQuery, которая включает в себя модули Ajax и эффектов, мы выпускаем «тонкую» версию, которая исключает эти модули. В общем, это исключает ajax, эффекты и устаревший код.

Размер файла (gzipped) примерно на 6 КБ меньше, 23,6 КБ против 30 КБ.

В настоящее время наиболее авторитетным ответом, по-видимому, является этот вопрос , в котором говорится, что «это пользовательская сборка jQuery, исключающая эффекты, ajax и устаревший код». Подробности будут объявлены в jQuery 3.0.

Я подозреваю, что обоснование исключения этих компонентов из библиотеки jQuery заключается в признании все более распространенного сценария использования jQuery в сочетании с другой средой JS, такой как Angular или React. В этих случаях использование jQuery в первую очередь предназначено для обхода и манипулирования DOM, поэтому исключение тех компонентов, которые либо устарели, либо предоставлены платформой, позволяет уменьшить размер файла примерно на 20%.

Стройное телосложение

Иногда вам не нужен ajax, или вы предпочитаете использовать одну из многих автономных библиотек, которые фокусируются на запросах ajax. И часто проще использовать комбинацию CSS и манипуляции с классами для всех ваших веб-анимаций. Наряду с обычной версией jQuery, которая включает в себя модули Ajax и Effects, мы выпустили «тонкую» версию, которая исключает эти модули. В общем, это исключает ajax, эффекты и устаревший код. В настоящее время размер jQuery очень редко влияет на производительность при загрузке, но тонкая сборка примерно на 6 тыс. Байт сжата по сравнению с обычной версией — 23,6 тыс. Против 30 тыс. Байт.

At CDNJS jquery.slim package is placed. It has a smaller size. What are the major differences from an original? A quick look at the code didn’t bring the answer, and at the jquery.com I’ve not found any reference about slim package.

So, what are the differences between jquery.js and jquery.slim.js ?

6 Answers 6

Looking at the code I found the following differences between jquery.js and jquery.slim.js:

In the jquery.slim.js, the following features are removed:

  1. jQuery.fn.extend
  2. jquery.fn.load
  3. jquery.each // Attach a bunch of functions for handling common AJAX events
  4. jQuery.expr.filters.animated
  5. ajax settings like jQuery.ajaxSettings.xhr, jQuery.ajaxPrefilter, jQuery.ajaxSetup, jQuery.ajaxPrefilter, jQuery.ajaxTransport, jQuery.ajaxSetup
  6. xml parsing like jQuery.parseXML,
  7. animation effects like jQuery.easing, jQuery.Animation, jQuery.speed

Along with the regular version of jQuery that includes the ajax and effects modules, we’re releasing a “slim” version that excludes these modules. All in all, it excludes ajax, effects, and currently deprecated code.

The file size (gzipped) is about 6k smaller, 23.6k vs 30k.

At this time, the most authoritative answer appears to be in this issue, which states «it is a custom build of jQuery that excludes effects, ajax, and deprecated code.» Details will be announced with jQuery 3.0.

I suspect that the rationale for excluding these components of the jQuery library is in recognition of the increasingly common scenario of jQuery being used in conjunction with another JS framework like Angular or React. In these cases, the usage of jQuery is primarily for DOM traversal and manipulation, so leaving out those components that are either obsolete or are provided by the framework gains about a 20% reduction in file size.

Sometimes you don’t need ajax, or you prefer to use one of the many standalone libraries that focus on ajax requests. And often it is simpler to use a combination of CSS and class manipulation for all your web animations. Along with the regular version of jQuery that includes the ajax and effects modules, we’ve released a “slim” version that excludes these modules. All in all, it excludes ajax, effects, and currently deprecated code. The size of jQuery is very rarely a load performance concern these days, but the slim build is about 6k gzipped bytes smaller than the regular version – 23.6k vs 30k.

I could see $.ajax is removed from jQuery slim 3.2.1

Below is the comment from the slim version with the features removed

Собственно не понятно, что происходит: window.jQuery || document.write(‘
Как это работает? и зачем?

  • Вопрос задан более года назад
  • 415 просмотров

Это fallback на случай, если из CDN jquery не загрузится.

Оцените статью