Reply not
Reply not

Reputation: 311

Unexpected token else exception on bundling JavaScript

I have some java Script files which is running fine when I'm not bundling them , but when I bundle them using SquishIt Framework It is showing error that unexpected token else on somewhere in new file in which all files are bundled together.

I've created an view inside which i Bundled all java script files and rendering it on my main page where I need those files.

That's my view of bundle

 <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
 <script src="https://unpkg.com/axios/dist/axios.min.js"></script>

@Html.Raw(
    SquishIt.Framework.Bundle.JavaScript()
    .Add("~/Areas/Streamer/Scripts/ckeditor/ckeditor.js?sdsd")
    .Add("~/Areas/Streamer/Scripts/global.js?v=1")
    .Add("~/Areas/Streamer/Scripts/common_vue.js?v=2")
   .Add("~/Areas/Streamer/Scripts/all-comments.js?v=3.902z2")
   .Render("~/Areas/Streamer/Scripts/combinedStreamer11234767_#.js")
   .ToLower())

This is my page where i am using it

 @section page_scripts{
 @Html.Partial("~/Areas/Streamer/Views/Shared/BundleAllComments.cshtml")
 }

if I am loading all files directly it is running fine , but after bundling it is showing error , what is the reason if someone guide , is it natural behavior of this framework?

Upvotes: 1

Views: 260

Answers (1)

AlexCuse
AlexCuse

Reputation: 18306

When I've seen this it is typically a problem with the minification - SquishIt only manages this for you. Sometimes it can be resolved by switching minifiers (eg from AjaxMin to Yui) but often it is a problem with a piece of content, or two pieces that have some kind of conflict between them.

I would first try switching minifiers and see if it works. If it doesn't, try removing files from your bundle one at a time (and loading the removed file directly). Once you identify the content causing the problem you can either fix it or serve two bundles in the referenced view. You might still be able to use SquishIt to minify the content but would still end up needing to serve two separate files using the latter option.

Upvotes: 0

Related Questions