Posted over 5 years ago. Visible to the public.
Using external JavaScript libraries [1.5d]
Just like we use gems on the server, we use third party JavaScript libraries in the browser. These typically provide functionality like:
- General support libraries like jQuery or lodash
- Wysiwyg HTML editors
- Datepickers
- Sliders
- Tooltips
- Dialogs
- ...
Choosing and installing a JavaScript library
Take a look at the popular lodash Archive library.
- Try to understand what it does.
- Lodash comes in two variants "Core build" and "Full build". Why is that? Why would you always prefer the "Core build" if sufficient?
- Why does it mention "x kB gzipped"? How is that important?
- Try to add lodash to MovieDB by simply downloading it and adding it to the asset pipeline.
Where is a good place to put it?
Can you find a way to make use of it? - Read about how we manage vendor libraries in projects that still use the Rails asset pipeline (not Webpacker)
- Lodash also provides "CDN copies". What is a CDN? Why do you think we don't use them?
- Lodash can also be installed via "npm". What is that? Why doesn't that work for the Rails Asset Pipeline?
- Often, JavaScript libraries come in "minified" versions. What does that mean? Is it important?
Exercise: Add a datepicker
In your MovieDB, add a "release date" field. Use the Rome date picker Archive to add a UI. Remember to use unobtrusive JavaScript.