Code Monkey home page Code Monkey logo

Comments (8)

pilavdzic avatar pilavdzic commented on July 4, 2024

I even moved all my js to a different folder /OldScripts so that it would start off ignoring all my js, but for some reason I get the following. I don't understand why cassette is looking in the oldscripts directory at all. Nowhere did I tell it to do anything with the files located there and that isn't the default scripts directory. It's like it looks at all your js everywhere, even files not in use yet and includes them all? Those are js files I want it to ignore. Please help!

Server Error in '/' Application.
Reference error in "OldScripts\jquery.unobtrusive-ajax.js", line 1. Cannot find "~\OldScripts\jquery-1.4.4.js".
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: Cassette.AssetReferenceException: Reference error in "OldScripts\jquery.unobtrusive-ajax.js", line 1. Cannot find "~\OldScripts\jquery-1.4.4.js".

from cassette.

andrewdavey avatar andrewdavey commented on July 4, 2024

The current documentation does not do an adequate job of explaining Cassette's default behaviour and how to configure it. I'll try to explain here and put some new docs online soon.

Cassette groups assets (js, css, etc) into "modules". Think of an asset module as a unit of deployment, like how you group C# files into an assembly. When your website is in production you don't want the client downloading lots of individual assets. So grouping related assets into modules means Cassette can serve them concatentated, minified, versioned and cached.

Given this "grouping of assets" behaviour, we need development-time to emulate the same client-side environment. While a particular page may not be using all the jQuery plugins you've got in a module, they will all be there in the production module. Therefore Cassette includes all module's scripts in the page when in debug mode.

So to solve your problem, first decide how you need to group your scripts. Create sub-directories in the Scripts folder and organize your files into them. I tend to have a "Scripts\lib" folder for third-party libraries, "Scripts\app" for general shared code and other sub-directories of Scripts for major parts of site functionality.

Now you can configure Cassette to use these sub-directories as "modules".
Please read the documentation, starting here: http://getcassette.net/documentation/configuration

Without a configuration, Cassette treats the entire application as a single module. That's why it's finding all scripts everywhere in your project.

I hope this helps. If you have more questions let me know, here or on twitter @andrewdavey Thanks!

from cassette.

pilavdzic avatar pilavdzic commented on July 4, 2024

Hi Andrew,
I did read this, but it leaves off a critical piece of information - how do you leave a file out of a module or an entire module out of development and production?

I assume you are not suggesting that if you have files in your project in development that you are not using yet it force you to complete all your code files before allowing you to compile and test?

What do I do in this (my real world case)? I have one file called Project.js that should be the module for the project page. I put it in /Scripts/Project then I have a file called Document.js that I put in /Scripts/Document per the instructions. According to the docs this will make each of these into a module. Great, no problem, I understood that and rearranged my files into this structure. But why does it make modules out of things in the OldScripts directory? And I don't understand what is the purpose of including the Project module on the Document page and vice versa. Even if I made these javascript files possible to run together on the same page, which would take substantial effort, I have users that don't have access to one of those pages every, so why would they need to load all of the js in my entire site when they only need that one module?

So, in short, my issue is:

How to exclude files from being included in modules, and how to exclude entire directories of javascript altogether from being in any module? Is this not possible?

I think I am missing something because what is the point of the modules if you always include all of them? It seems to me your whole library is designed around including some modules but not others, but the part that isn't clear in the documentation is that it says if you include a JS file it will include all the files in that folder - but I didn't include that js file - it still tries to include an entire folder of js files that are not in use in my project currently?

Perhaps you are not able to answer my question because it is not supposed to behave this way, it is only doing it in my case.

What happens if I have old style <script src=""> includes within the pages as well, are these incompatible with cassette? Because I have some things I do not want to migrate over to the cassette way of doing things for various reasons. Is it possible to use cassette for some includes but the old style way for others?

from cassette.

pilavdzic avatar pilavdzic commented on July 4, 2024

P.S. I realize I wasn't clear at the very beginning of my question when I said
" it includes all the .js files in my /scripts directory from the moment the package is installed regardless."

I know it is supposed to do that. It's supposed to make a module of each Directory like /Scripts/Project and Scripts/Document. I get it.

What I assume it's not supposed to do it include the Project and Document modules on every page, as well as another one in the OldScripts directory which is not a subdirectory of /Scripts, despite my not having any Asset.Reference calls.

I wish there was a way to upload files so I could create an example for you of the bug. The more I think about it the more I realize it can't possibly be me, there is a bug here. The docs do not state that without using Asset.Reference it will include all js in every subfolder in the project on it's own. If that's intended functionality that's messed up.

from cassette.

andrewdavey avatar andrewdavey commented on July 4, 2024

Can you paste your CassetteConfiguration.cs file into a comment here? That will help me see how you've configured Cassette and give you some advice.

You can always email me [email protected] if you want to send a sample project that reproduces the bug.

from cassette.

pilavdzic avatar pilavdzic commented on July 4, 2024

Thank you very much for your assistance.

My cassetteConfiguration.cs is the default:

using Cassette;

namespace UsaidInfo
{
///

/// Configures the Cassette asset modules for the web application.
/// </summary>


public class CassetteConfiguration : ICassetteConfiguration
{
    public void Configure(ModuleConfiguration moduleConfiguration, ICassetteApplication application)
    {
        // TODO: Configure your asset modules here...
        // Please read http://getcassette.net/documentation/configuration
        // *** TOP TIP: Delete all ".min.js" files now ***
        // Cassette minifies scripts for you. So those files are never used.

        // Without a configuration, Cassette uses a simple set of defaults:
        //
        // Scripts
        //    Single module from the application's root directory
        //    Files included: *.js and *.coffee
        //    Files excluded: File names ending with "-vsdoc.js"
        //    CoffeeScript compilation enabled
        //
        // Stylesheets
        //    Single module from the application's root directory
        //    Files included: *.css and *.less
        //    File excluded: none
        //    LESS compilation enabled
        //
        // HTML Templates
        //    Single module from the application's root directory
        //    Files included: *.htm and *.html
        //    Files excluded: none
        //    Compilation disabled
    }
}

}

I'll email you, thanks again for the assistance, I really want to get your library to work for me, I hear it's great and works for others, I just have a large project that has something different in it I guess...

from cassette.

andrewdavey avatar andrewdavey commented on July 4, 2024

OK let's try configuring some modules. We'll use the example given here http://getcassette.net/documentation/configuration/persubdirectorysource

Basically, try using this:

public void Configure(ModuleConfiguration moduleConfiguration, ICassetteApplication application)
{
    moduleConfiguration.Add(
        new PerSubDirectorySource<ScriptModule>("Scripts")
        {
            FilePattern = "*.js;*.coffee",
            Exclude = new Regex("-vsdoc\\.js$") // Excludes the VS documentation files
        }
    );
}

from cassette.

andrewdavey avatar andrewdavey commented on July 4, 2024

BTW: I'm sorry for the confusion getting started with Cassette has caused. I've been juggling coding the library, documenting how it works, building the website and still doing client work as well. Things have happened a bit out of order perhaps! :)

I really appreciate the feedback you're providing and will be fixing the "out of the box" behaviour soon. Getting the most out of Cassette does involve configuration, but obviously there should be more sensible defaults.

from cassette.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.