Deep-dive on the Next Gen Platform. Join the Webinar!

Skip Navigation
Show nav
Dev Center
  • Get Started
  • Documentation
  • Changelog
  • Search
  • Get Started
    • Node.js
    • Ruby on Rails
    • Ruby
    • Python
    • Java
    • PHP
    • Go
    • Scala
    • Clojure
    • .NET
  • Documentation
  • Changelog
  • More
    Additional Resources
    • Home
    • Elements
    • Products
    • Pricing
    • Careers
    • Help
    • Status
    • Events
    • Podcasts
    • Compliance Center
    Heroku Blog

    Heroku Blog

    Find out what's new with Heroku on our blog.

    Visit Blog
  • Log inorSign up
Hide categories

Categories

  • Heroku Architecture
    • Compute (Dynos)
      • Dyno Management
      • Dyno Concepts
      • Dyno Behavior
      • Dyno Reference
      • Dyno Troubleshooting
    • Stacks (operating system images)
    • Networking & DNS
    • Platform Policies
    • Platform Principles
  • Developer Tools
    • Command Line
    • Heroku VS Code Extension
  • Deployment
    • Deploying with Git
    • Deploying with Docker
    • Deployment Integrations
  • Continuous Delivery & Integration (Heroku Flow)
    • Continuous Integration
  • Language Support
    • Node.js
      • Working with Node.js
      • Troubleshooting Node.js Apps
      • Node.js Behavior in Heroku
    • Ruby
      • Rails Support
      • Working with Bundler
      • Working with Ruby
      • Ruby Behavior in Heroku
      • Troubleshooting Ruby Apps
    • Python
      • Working with Python
      • Background Jobs in Python
      • Python Behavior in Heroku
      • Working with Django
    • Java
      • Java Behavior in Heroku
      • Working with Java
      • Working with Maven
      • Working with Spring Boot
      • Troubleshooting Java Apps
    • PHP
      • PHP Behavior in Heroku
      • Working with PHP
    • Go
      • Go Dependency Management
    • Scala
    • Clojure
    • .NET
      • Working with .NET
  • Databases & Data Management
    • Heroku Postgres
      • Postgres Basics
      • Postgres Getting Started
      • Postgres Performance
      • Postgres Data Transfer & Preservation
      • Postgres Availability
      • Postgres Special Topics
      • Migrating to Heroku Postgres
    • Heroku Key-Value Store
    • Apache Kafka on Heroku
    • Other Data Stores
  • AI
    • Working with AI
  • Monitoring & Metrics
    • Logging
  • App Performance
  • Add-ons
    • All Add-ons
  • Collaboration
  • Security
    • App Security
    • Identities & Authentication
      • Single Sign-on (SSO)
    • Private Spaces
      • Infrastructure Networking
    • Compliance
  • Heroku Enterprise
    • Enterprise Accounts
    • Enterprise Teams
    • Heroku Connect (Salesforce sync)
      • Heroku Connect Administration
      • Heroku Connect Reference
      • Heroku Connect Troubleshooting
  • Patterns & Best Practices
  • Extending Heroku
    • Platform API
    • App Webhooks
    • Heroku Labs
    • Building Add-ons
      • Add-on Development Tasks
      • Add-on APIs
      • Add-on Guidelines & Requirements
    • Building CLI Plugins
    • Developing Buildpacks
    • Dev Center
  • Accounts & Billing
  • Troubleshooting & Support
  • Integrating with Salesforce
  • Language Support
  • Scala
  • Using Node.js to Perform JavaScript Optimization for Play and Scala Applications

Using Node.js to Perform JavaScript Optimization for Play and Scala Applications

English — 日本語に切り替える

Last updated May 30, 2024

Table of Contents

  • Using multiple buildpacks

Many sbt plugins perform operations requiring a JavaScript engine. For example, the sbt-rjs plugin performs RequireJs optimization, and the sbt-uglify plugin performs UglifyJS optimization. By default, these plugins use Trireme, which runs Javascript inside the JVM. The Trireme engine may be sufficient for small operations, but it’s performance can suffer when operating on large numbers of files.

To improve the performance of these plugins, it may be necessary to use a native Node.js engine. If you find that your build process hangs indefinitely during a JavaScript step, then you likely need to change engines. In this article, you’ll learn how to configure your project to install Node.js and use it to execute your JavaScript optimizations for a Play or Scala project.

Using multiple buildpacks

In order to use Node.js with Scala on Heroku, you must configure your project to use both the Scala buildpack and the Node.js buildpack. This is done with the heroku buildpacks command.

First, add the Node.js and Scala buildpacks to your application by running this:

$ heroku buildpacks:clear
$ heroku buildpacks:add heroku/nodejs
$ heroku buildpacks:add heroku/scala

Then confirm the execution order by running this command:

$ heroku buildpacks
=== nameless-brushlands-4859 Buildpack
1. heroku/nodejs
2. heroku/scala

This ensures Heroku will run the Node.js buildpack first, and the Scala buildpack second.

In order for the Node.js buildpack to execute, your project must also have a package.json file. In this file, you can define the version of Node.js to install. Create the package.json file in the root of your project and put the following code in it:

{ "engines": { "node": "4.0.0" } }

You can also leave it empty (just {}) to always pick up the latest version.

Then add this file to your Git repository by running the following commands:

$ git add package.json
$ git commit -m "Added package.json"

Finally, configure sbt to use the Node.js engine by setting SBT_OPTS thusly:

$ heroku config:set SBT_OPTS="-Dsbt.jse.engineType=Node"

Now you’re ready to deploy. Run the following command:

$ git push heroku master
[master 6d8842c] redeploy
Counting objects: 1, done.
Writing objects: 100% (1/1), 184 bytes | 0 bytes/s, done.
Total 1 (delta 0), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Fetching custom git buildpack... done
remote: -----> Node.js app detected
remote:
remote: -----> Reading application state
remote:        package.json...
remote:        build directory...
remote:        cache directory...
remote:        environment variables...
remote:
remote:        Node engine:         unspecified
remote:        Npm engine:          unspecified
remote:        Start mechanism:     Procfile
remote:        node_modules source: package.json
remote:        node_modules cached: false
...
remote: -----> Fetching custom git buildpack... done
remote: -----> Play 2.x - Scala app detected
remote: -----> Installing OpenJDK 1.8... done
remote: -----> Priming Ivy cache (Scala-2.11, Play-2.3)... done
remote: -----> Running: sbt update
...
remote:        [info] Done packaging.
remote:        [success] Total time: 4 s, completed Jan 29, 2015 2:51:10 PM
remote: -----> Dropping ivy cache from the slug
remote: -----> Dropping sbt boot dir from the slug
remote: -----> Dropping compilation artifacts from the slug
remote:
remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote:
remote: -----> Compressing... done, 98.8MB
remote: -----> Launching... done, v6
remote:        https://play-node-test-1234567890ab.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/play-node-test.git
   99109c2..6d8842c  master -> master

As the deploy process executes, you will see that Heroku installs Node.js (which will generate some warning that you can ignore – these are due to the minimal package.json file). When the sbt process executes it will use the Node.js engine.

For more information on configuring the sbt JavaScript engine, see the sbt-js-engine documentation. For more information on using Scala on Heroku, see the DevCenter documentation for Scala support.

Keep reading

  • Scala

Feedback

Log in to submit feedback.

Information & Support

  • Getting Started
  • Documentation
  • Changelog
  • Compliance Center
  • Training & Education
  • Blog
  • Support Channels
  • Status

Language Reference

  • Node.js
  • Ruby
  • Java
  • PHP
  • Python
  • Go
  • Scala
  • Clojure
  • .NET

Other Resources

  • Careers
  • Elements
  • Products
  • Pricing
  • RSS
    • Dev Center Articles
    • Dev Center Changelog
    • Heroku Blog
    • Heroku News Blog
    • Heroku Engineering Blog
  • Twitter
    • Dev Center Articles
    • Dev Center Changelog
    • Heroku
    • Heroku Status
  • Github
  • LinkedIn
  • © 2025 Salesforce, Inc. All rights reserved. Various trademarks held by their respective owners. Salesforce Tower, 415 Mission Street, 3rd Floor, San Francisco, CA 94105, United States
  • heroku.com
  • Legal
  • Terms of Service
  • Privacy Information
  • Responsible Disclosure
  • Trust
  • Contact
  • Cookie Preferences
  • Your Privacy Choices