0

In one of my razor page I have the following in the scripts section

   @Scripts.Render("~/bundles/script1")
   @Scripts.Render("~/bundles/script2")
   @Scripts.Render("~/bundles/script3")

The problem is it will render 3 JavaScript files. Is there any way they can be bundled in one file without changing the BundleConfig file?

Thanks,

Felix Cen
  • 733
  • 1
  • 6
  • 24

3 Answers3

2

The problem is it will render 3 JavaScript files. Is there any way they can be bundled in one file without changing the BundleConfig file?

No, you will have to change your BundleConfig.

Well, if you want to reuse script1 in another page, how will you do that?

Make a script bundle include another script bundle

Community
  • 1
  • 1
Erik Philips
  • 53,428
  • 11
  • 128
  • 150
0

Yes you can create a Bundle containing all the files from Script1, 2 and 3 Bundles and then lets say if its called ScriptAll bundle then you can render it with 1 line. Unfortunately you will have to change your BundleConfig

@Scripts.Render("~/bundles/scriptall")
Mihir Solanki
  • 333
  • 1
  • 6
0

why would You do this ? copy the code from these 3 files and paste it to one.js file then pass it to bundles.

joint_ops
  • 312
  • 1
  • 5
  • 20
  • Well, if you want to reuse script1 in another page, how will you do that? – Felix Cen Mar 08 '16 at 18:43
  • if you want to use your scripts on all views assigned to Your layout You should pass it to BundleConfig , but if Your script file is executed on only one of Your view's You should load it into view by @Scripts.Render section. You don't want to load unnecessary js files to Your Views ;) – joint_ops Mar 08 '16 at 22:55