1

I'm currently attempting to refactor my repeated JavaScript code from my xyz.scala.html files into a separate main.js file, which can then be linked to using something like the below (from my scala.html files):

<script src='@routes.Assets.at("javascripts/main.js")'><script>

And using the below in my conf/routes file:

GET     /js/*file               controllers.Assets.at(path = "/public/javascripts", file)

Having Googled around I'm struggling to find a simple way of using JS from a file in my Play Framework application and setting up the conf/routes file.

Does anyone know a simple way of getting this to work?

1 Answer 1

1

Public assets folders

Public assets folders

Record in the routes file

GET     /assets/*file               controllers.Assets.versioned(path="/public", file: Asset)

Script loading in twirl template

<script src="@routes.Assets.versioned("javascripts/hello.js")" type="text/javascript"></script>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.