The attached compiler() function below applies JavaScript behavior to matching HTML elements as they enter the DOM. This works like an Unpoly compiler for apps that don't use Unpoly...
...Custom Elements or any other mechanism that pairs JavaScript with HTML elements. The compiler() function is also a lightweight replacement for our legacy $.unobtrusive() helper (no jQuery required).
Usually, Unpoly compiler destructors are returned from the compiler function. However, when using async compiler functions, you can not register destructors via return. This will not work: up.compiler('my-example...
Remember How to skip Sprockets asset compile during Capistrano deployment and Automatically skipping asset compilation when assets have not changed? Turns out there is an even better way to speed...
...up Capistrano deployments with asset compilation – and it's even simpler. Adding the asset cache directory to symlinked directories Popular asset managers for Rails are Sprockets and Webpacker. Both keep...
...We're using it in our latest Rails applications. For tests, we want to compile assets like for production. For parallel tests, we want to avoid 8 workers compiling the...
When assets did not change, we do not want to spend time compiling them. Here is our solution for all that. Its concept should work for all test...
Webpack builds can take a long time, so we only want to compile when needed. This card shows what will cause Webpacker (the Rails/Webpack integration) to compile your assets.
...it is recommended to boot a webpack dev server using bin/webpack-dev-server. The dev server compiles once when booted. When you access your page on localhost before the initial compilation, the...
Use the compile function to change the original DOM (template element) before AngularJS creates an instance of it and before a scope is created. Use the pre-link function to...
...implement logic that runs when AngularJS has already compiled the child elements, but before any of the child element's post-link functions have been called. Use the post-link...
...OS WebKit engine, and only code written in C, C++, and Objective-C may compile and directly link against the Documented APIs (e.g., Applications that link to Documented APIs through...
...This significantly speeds up installation of the gem, as Nokogiri no longer needs to compile libxml2. However, this also means that for each security issue with libxml2, Nokogiri maintainers have...
...libraries because of that. # Quick check Nokogiri::VersionInfo.instance.libxml2_using_system? Instructions Nokogiri can compile its C extensions against system libraries, but if any matching pre-built binaries are available...
...target attribute may be fetched from the database/your record. This results in the following compiler (when using Unpoly): import StreetMap from 'street_map' up.compiler('.map', function(map) { let targetLocation = map.getAttr...
...and why we used modules in the first place. We "copy" (parts of) the compiler function by creating a new StreetMap instead of using the existing instance of our map...
...a common example: Clear Search The HTML above is being activated with an Unpoly compiler like this: up.compiler('[filter]', function(filterForm) { const resetButton = filterForm.querySelector('[filter--reset]') const queryInput = filterForm.querySelector('[filter...
...will announce it as a "button" when focused: Clear Search Now change your Unpoly compiler to activate the button on keydown in addition to click: up.compiler('[filter]', function(filterForm) {
For applications coming with lots of stylesheets and scripts, asset compilation might take quite long. This can be annoying when deploying a release that does not actually change assets.
...your app uses Sprockets, you can simply skip asset compilation and re-use the previous release's assets. [1] That is especially easy via Capistrano. Capistrano will automatically symlink your...
...is easily doable by using the asynchronous import function. Say we have an unpoly compiler that sets up TinyMCE like this (code is somewhat simplified): // TinyMCE as part of the...
...AJAX, and resolve a promise as soon as the JavaScript has been loaded. The compiler above can thus be rewritten like this: // TinyMCE is a separate bundle! import 'tinymce/skins/ui/oxide/skin.min.css' // CSS...
var player = flowplayer($element) player.play() Framework activation layers (like Angular directives, Unpoly compilers, React components, $.unobtrusive()) are all layer 3. It's simpler to just have one layer...
...In the future library developers will no longer ship JavaScript as Angular directives, Unpoly compilers or anything framework-specific. It will all be Custom Elements. Custom elements let you teach...
%button(file-input-clear) Clear file Now we can the define an Unpoly compiler (or any other UJS mechanism) to look for a file-input attribute and run code...
...your code aware of feature-flags For this example we will use an Unpoly compiler to build a [poll] attribute. This attribute causes an element to be reloaded from the...
...to show statistics of bundle sizes. Generated file will automatically open in your browser. // Compile with NODE_ENV=production bin/rake assets:precompile const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin; environment.plugins.append...
...BundleAnalyzer', new BundleAnalyzerPlugin({ analyzerMode: 'static' }) ) Then compile using the production environment. In a Webpacker project, this can be done with NODE_ENV=production bin/webpack An interactive graph like this will...
Unpoly 3.11.0 is a big release, shipping many features and quality-of-life improvements requested by the community. Highlights include...
Webpack(er): Serving identical assets from all servers. Capistrano: Speeding up asset compile during deploy . Only compiling production packs on the server Asset compilation takes quite some time...
...and slows down deployments. Let's only compile packs that are relevant, then. No need for specs and other development packs on the servers. Create a directory "packs_production" right...
...load it all up front, I would recommend to load large libraries from the compilers that need it. Compilers are also a good place to track whether the library has...
This card describes four variants, that add a more intuitive workflow when working with nested attributes in Rails + Unpoly:
...Don't touch the asset pipeline or this spec will take 30 seconds to compile assets that we don't need allow_any_instance_of(ActionView::Base).to receive(:javascript...
YJIT is Ruby's default just-in-time compiler. It is considered production-ready since Ruby 3.2 (source). To activate YJIT you need two steps: Your ruby binary needs to...
...be compiled with YJIT support. You need to enable YJIT. Getting a Ruby with YJIT support We usually install Ruby with tools like rbenv or asdf. This compiles the ruby...
...all descending (inheriting) classes. This is rarely what you want. Class variables are bound at compile-time Like unqualified constants, class variables are bound to your current scope when the...
Unpoly's [up-observe], [up-autosubmit] and [up-validate] as well as their programmatic variants up.observe() and up.autosubmit...