andrewdavey / cassette Goto Github PK
View Code? Open in Web Editor NEWManages .NET web application assets (scripts, css and templates)
Home Page: http://getcassette.net
License: MIT License
Manages .NET web application assets (scripts, css and templates)
Home Page: http://getcassette.net
License: MIT License
I assume one would use "Assets.Scripts.ExternalReference" to include a script from a CDN, but in case that resource is unavailable, one would write the following script:
<script type="text/javascript"> !window.jQuery && document.write(unescape('%3Cscript src="@Url.Content("~/Scripts/libs/jquery-1.6.2.min.js")"%3E%3C/script%3E'))</script>It's possible to put this script inside another .js file, but maybe it's an idea to add an overload to ExternalReference that will take both an external url (CDN) and a local url (fallback).
Ps. sorry if this isn't the right place to post suggestions!
I get this error if I have the following line in the <system.webServer> section in my web.config (IIS7)
<urlCompression doDynamicCompression="true" dynamicCompressionBeforeCache="true" />
Without this, everything seems OK, otherwise, I can't even load a single page..
From: andrewdavey/knapsack#16
It seems that Cassette interferes with glimpse or I don't know the correct Cassette config!. (http://getglimpse.com/)
To repro:
New MVC3 project.
Use Nuget to install Glimpse MVC3
Ensure Glimpse running OK
Set Project to use IIS Express --> Run website in Debugger - Glimpse works OK
Use Nuget to install Cassette.Web --> Run website in debugger - Glimpse doesn't work. Blank screen shown in browser.
IE 6 and 7 need some mhtml magic.
IE 8 - need to check for max image size and not convert those that are too big.
I have scripts (amplify.js stuff) that I removed from the project while I'm testing and I killed the Cassini (WebDev) web server. I rebuilt the code... I reran the page. I'm still getting the files included in the project...
<script src="/Scripts/amplify.js?e90b20fc3cb0acb9e50c1134fc430194335815a5" type="text/javascript"></script> <script src="/Scripts/amplify.min.js?83c1d95e2a30458f77e9a8ebd14826639df78f6e" type="text/javascript"></script>Nothing references amplify. I just added it to my project and did not use it anywhere.
Now, I excluded the js files from my project and it's still happening??
I'm having the same problems as issue 18, where I am receiving a YSOD with 'An item with the same key has already been added'. I'm using version 0.5.4 though which has not solved the issue, as that one seems to be a different cause.
Having worked through the issue I have modified the latest source code in 2 places which seems to have fixed the issue, although I'm not sure whether the fix is correct or not. I have:
ModuleContainer.cs, line 27:
modulesByScriptPath = (
from module in this.modules
from asset in module.Assets
select new { asset.Path, module }
).Distinct().ToDictionary(x => x.Path, x => x.module, pathComparer);
UnresolvedModule.cs, line 60:
var modulesByAssetPath = (
from module in unresolvedModules
from asset in module.assets
select new { asset.Path, module }
).Distinct().ToDictionary(x => x.Path, x => x.module.path, StringComparer.OrdinalIgnoreCase);
To give some background as it stands my web.config looks like:
<cassette moduleMode="OffInDebug">
<scripts>
<add path="Scripts/Lib" />
</scripts>
<styles>
<add path="Content/Css/" />
</styles>
</cassette>
Without Scripts/Lib everything works OK. In Scripts/Lib I have a number of 3rd party JS files (jQuery, jQuery UI etc.) and a modules.txt file.
In addition, the exception that is thrown is not particularly useful as it points only to ExceptionCachedManager as the exception is rethrown from there. Can the stack trace be preserved, something along the lines of:
Line 20, in the constructor:
PreserveStackTrace(exception);
Add:
private static void PreserveStackTrace(Exception exception)
{
var preserveStackTrace = typeof(Exception).GetMethod("InternalPreserveStackTrace",
BindingFlags.Instance | BindingFlags.NonPublic);
preserveStackTrace.Invoke(exception, null);
}
Although the YSOD still gives the unhelpful stack trace (it does not look at the Stack Trace of the exception but does some other magic to determine the 'incorrect' stack trace), the stack trace logged in event viewer and available elsewhere will be valid and point in the right direction.
Thanks,
Adam
Add configuration setting to run JSLint on JavaScript because no one hates your code quite as much as Crockford does!
Probably run the lint when the script modules are being built. Throw an exception on failure?
Hello,
Sorry for posting this here but I can't find any documentation.
I found one page on this github wiki that told me how to use
Assets.Scripts.Reference() and I am migrating my site over to using that and this works...
But how do you include a css file?
Is it Assets.Style.Reference() or Assets.Styles.Reference or Assets.Css.Reference or something?
Is it just me that does not have intellisense in Razor cshtml files?
Obviously I did a google search for "cassette javascript css" and "casseette javascript styles" and many other such searches and all the top pages returned don't have any useful info...
new ExternalStylesheetModule("reset", "http://example.com/cdn/reset.css")
For mobile devices I want to include certain stylesheets and set the "media" attribute.
Currently I don't see how to do that using Cassette and am forced to usedirectly the element.
Most of our JavaScript references are absolute paths which Cassette seems to treat as relative paths.
Eg.
/// <reference path="/resources/scripts/shared/utils.js"/>
/// <reference path="/resources/scripts/shared/location.js"/>
/// <reference path="/resources/scripts/shared/sector.js"/>
/// <reference path="/resources/scripts/shared/account.js"/>
We get errors like
The file "resources/scripts/account/edit//resources/scripts/shared/utils.js" is referenced by "resources/scripts/account/edit/contact.js" but cannot be found.
I think it should support absolute paths in reference paths
Add support for external module config in module.txt
[external]
http://cdn.com/jquery.js
[assets]
jquery.js
I installed Mindscape Workbench to support Coffeescript.
Now I understand that Cassette is able to compile .coffee files into .js files, which is great.
However, the Mindscape Workbench alread generates a .js file at design time.
Now I could directly reference the generated .js file (using Assets.Scripts.Reference()), but I'm not sure how to declare dependent scripts in my .coffee file. The Mindscape Workbench doesn't put # comments into the .js file.
So I thought I would reference the .coffee file directly and let Cassette handle the compilation so that the # reference statement works.
That works great, however, Cassette includes both it's own version of the generated .js file as well as the design-time generated /js file by Mindscape Workbench.
Any tips on how to resolve this?
Thanks
To improve webpage performance it is advisable to render included scripts at the bottom of the page.
However, some script libraries don't work correctly when loaded too late; they need to be included from within the tag (like modernizr.js).
Is this already possible? If so, where can I find documentation?
After updating from cassette 0.5.2 to 0.5.4, Cassette suddenly stops rendering scripts from certain modules (I have 4 script modules, of which only one gets rendered).
I'm not sure what's going on, but stepping through the debugger shows me that Graph.TopologicalSort returns only one path node, causing to only render a single module (the one that is defined with location="Head", all modules with location="Body" are not being rendered).
My web.config looks like this:
<cassette moduleMode="OffInDebug">
<scripts>
<add path="Scripts/libs" location="Body"/>
<add path="Scripts/app" location="Body"/>
<add path="Scripts/ui" location="Body"/>
<add path="Scripts/enhancements" location="Head"/>
</scripts>
<styles>
<add path="Content" />
<add path="Areas" />
</styles>
<htmlTemplates>
</htmlTemplates>
</cassette>
My view looks like this:
@{
Assets.Scripts.Reference("scripts/libs/plugins.js");
Assets.Scripts.Reference("scripts/enhancements/modernizr-2.0.6.js");
Assets.Scripts.Reference("scripts/ui/panelbarmenu.js");
Assets.Scripts.Reference("scripts/app/init.coffee");
Assets.Scripts.Reference("scripts/ui/tabstrip.coffee");
Assets.Scripts.Reference("scripts/ui/cssbehaviors.coffee");
}
<!doctype html>
<head>
@Assets.Scripts.Render("Head")
</head>
<body>
@RenderBody()
@Assets.Scripts.Render("Body")
</body>
</html>
I'm clueless, so hopefully you see what's going on.
Thanks!
Below is the following error I receive when I have added the cassette nuget package:
No changes have been made and no scripts have been referenced yet
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: System.ArgumentException: An item with the same key has already been added.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[ArgumentException: An item with the same key has already been added.] Cassette.Web.ExceptionCachedManager.CreatePageAssetManager(HttpContextBase httpContext) +92 Cassette.Web.CassetteHttpModule.b__0(Object sender, EventArgs e) +173 System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +80 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +266
Many thanks, Dan Atkinson
Investigate the different script loaders, such as LABjs, require.js and head.js.
Could Cassette provide automatic support for these? Would that even make sense, given Cassette's module-based approach to scripts?
e.g.
border-radius: 5px;
becomes
border-radius: 5px;
-moz-border-radius: 5px;
etc
In NuGet package manager I update Cassete and in the same time I decided to update AjaxMin from 4.13 to latest (4.19). NuGet manager successfully updated references in my project file. However, it appears that Cassete has a reference to particular version of AjaxMin. I got following exception:
Could not load file or assembly 'AjaxMin, Version=4.13.4076.28499, Culture=neutral, PublicKeyToken=24297a69a7eae424' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
(No stack trace available)
My guess it's related with reference in project file
https://github.com/andrewdavey/cassette/blob/master/src/Cassette/Cassette.csproj
to AjaxMin assembly with strong name and particular version.
When running in debug mode, everything works as it should, but as soon as I set debug="false" andrefresh my page, I receive a javascript error that a function is expected. Looking at the source of the error, it is caused in modernzir.min.js.
Could there be a minification issue on already minified scripts?
JavaScript libraries such as jQuery UI require CSS to render correctly. So perhaps allow a JS file to reference a CSS file. Then the page only needs to reference the JS file and the required CSS module is also added.
Hi Andrew,
Further to our Tweets, I set up a default ASP.NET MVC test project to try Cassette, but when I reference the jQuery vsdoc file from within a script file I get the following exception:
The file "scripts/Lib/jquery-1.5.1-vsdoc.js" is referenced by "scripts/TestScript/Core.js", but cannot be found. Either add "scripts/Lib/jquery-1.5.1-vsdoc.js" or change the reference(s) to a file that exists.
Here is the stack trace:
[FileNotFoundException: The file "scripts/Lib/jquery-1.5.1-vsdoc.js" is referenced by "scripts/TestScript/Core.js", but cannot be found. Either add "scripts/Lib/jquery-1.5.1-vsdoc.js" or change the reference(s) to a file that exists.]
Cassette.Web.ExceptionCachedManager.CreatePageAssetManager(HttpContextBase httpContext) +75
Cassette.Web.CassetteHttpModule.b__0(Object sender, EventArgs e) +118
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +148
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
I've copied the jQuery vsdoc file into a /script/Lib sub-folder.
Am I doing something wrong?
Cheers
When a add a silverligth application a get this error
[ArgumentException: An item with the same key has already been added.]
Cassette.Web.ExceptionCachedManager.CreatePageAssetManager(HttpContextBase httpContext) +75
Cassette.Web.CassetteHttpModule.b__0(Object sender, EventArgs e) +118
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +148
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
I have shared views which are used in 2 different situations (Desktop/iPad). I have a test in my Site.Master to include the CSS for the iPad (lots of overriden styles) if the requesting user is using an iPad. Unfortunately, Cassette puts all of this stuff together, it seems.
How can I accomplish this, given that they're the same exact views?
Certain views require scripts & css that are specific for that view.
What is the recommended approach:
With javascript files, Cassette knows the correct order in which to render the scripts, based on the defined dependencies using the xml comment /// <reference ... />.
However, I have some stylesheets where it matters in which order they are included.
For example, I have Styles.css defining a default color for elements, and a Buttons.css defining another color for elements.
If I would manually include Style.css before Buttons.css, it would work as needed.
However, Cassette renders Buttons.css before Style.css.
I could of course use the !important value or be more specific in my Buttons.css so that its rules will overrule.
But it would be great if I could control dependencies between .css files just like we can with .js files.
Maybe something like:
By default every path you add cassette will combine all JavaScript files in the folders into modules.
On certain folders I would like to be able to specify to cassette to ignore combining the JavaScript on that folder and it's sub folders.
I would still like to have cassette manage (minification, visioning etc.) but as individual resources.
Maybe this could be done in the configuration like
<add path="resources/scripts/controllers" module="Off" />
Create MSBuild task to allow bundle building at compile-time.
Should generate the equivalent of the bundle cache (xml manifest + .bundle files).
Will probably need to enhance start-up code to skip cache validation and generation.
We have a MVC website which uses N2 CMS which is a webforms based content management system with a nested admin interface that sits in your application.
Since adding cassete it has broken the WebResource.axd requests which started to return empty content.
I've fixed this in my fork https://github.com/nazjunaid/cassette, I wasn't sure if it should ignore all .axd requests so I just ignore requests specifically to those resources.
It might not be an elegant solution but seems to work now maybe this should be moved to an ignores section in the configuration?
Found threads with people posting similar problems with other modules
http://forums.asp.net/t/1161118.aspx/1
http://forums.asp.net/t/1017291.aspx/1
When deployed in release mode and accessing a web site that uses Cassette, Cassette is not finding my external script module.
I have this reference in my CassetteConfiguration:
new ExternalScriptModule("GoogleMapsApi", "https://maps-api-ssl.google.com/maps/api/js?sensor=false")
And I reference it in other .js files like:
All is well in a debug deployment, however when I deploy in release I get errors like:
Reference error in "googlemap.Map.js", line 1. Cannot find "~\GoogleMapsApi"
I'm using 0.6 from NuGet.
The docs state that to include a .js file you do this:
Assets.Scripts.Reference("scripts/utils/date.js");
Assets.Scripts.Reference("scripts/widgets/calendar.js");
But the bug is, even if I don't include those lines of code at all, it does the same thing as if you do... it includes all the .js files in my /scripts directory from the moment the package is installed regardless.
I have not been able to determine a way to include certain .js files or modules in the scripts directory on certain pages but not others. To make matters worse, I have some script files which should never be included on all pages, only on certain pages from which I reference them, as they interfere with others.
I install cassette and now my site is completely broken, before I have had a chance to configure anything, it apparently includes all files into every page. Is there a way to stop it from doing this? I am not sure if this is a default or a bug? But it sure makes it frustrating to migrate a site with existing javascript over to cassette if you were not using it from the beginning.
It seems that people will want control over what asset processing occurs (Sass, Less, JSLint, JSHint, CoffeeScript, etc) . Configuring all this in web.config will be awful. A better approach will be a code-based configuration system.
On application start-up an asset pipeline initializer should be called. This will define the pipeline stages. The nuget package can put a sensible default into the project.
I'm imagining something like:
AssetPipelines.Scripts = new Pipeline[] {
JSLint(),
CompileCoffeeScript(),
Concatenate(),
MSAjaxMinify()
};
This will enable people to insert their own asset pipeline processors as well by implementing a simple interface.
For per-module configuration, a Conditional
pipeline stage wrapper could be used:
new Conditional(module => module.Path != "scripts/third-party", JSLint())
I've just updgraded from 0.5.2 to 0.5.4 and I get the error message "An item with the same key has already been added." Here is the stack trace:
[ArgumentException: An item with the same key has already been added.]
Cassette.Web.ExceptionCachedManager.CreatePageAssetManager(HttpContextBase httpContext) +92
Cassette.Web.CassetteHttpModule.b__0(Object sender, EventArgs e) +173
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +80
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +270
This was raised as issue #18, which has recently been closed.
Any idea how I can fix this?
e.g.
new DirectorySource<ScriptModule>("Content/Scripts/lib/")
should be the same as
new DirectorySource<ScriptModule>("Content\\Scripts\\lib")
I've tried disabling cassete's handling of images using code bellow
modules.Customize<StylesheetModule>(
module => module.Processor = new StylesheetPipeline
{
CompileLess = false,
ConvertImageUrlsToDataUris = false,
});
I set ConvertImageUrlsToDataUris to false but it still tries to handle images in the project when viewing source I can see lots of the
<link href="/resources/styles/common/images/ui-icons_ef8c08_256x240.png?5a3fd02264b7d5d6ed8b22ad7de42e0859997bff" type="text/css" rel="stylesheet"/>
type tags on the page.
A page may wish to use it's own script loader (like LABjs, head.js or require.js). So instead of rendering script elements, allow the page to get the list of asset URLs.
@Html.ScriptUrls()
?
The current default is for each sub-directory of "scripts", "styles", "htmlTemplates" to be a module.
This is confusing for new users, especially when it comes to stylesheets.
An alternative default is to treat the entire web application as a single module. So the default path is "~/" for each asset type.
This would be simpler for small web applications. More complex apps can always edit the web.config for more advanced module definitions.
Create and Publishn MVC3 app with Cassette.Web 0.5.2 to a Server 2008 R2 box with standard permissions (i.e. nothing's been modified). The following error occurs without any additional code changes outside of installing the NuGet Package
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: System.IO.IsolatedStorage.IsolatedStorageException: Unable to create the store directory. (Exception from HRESULT: 0x80131468)
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[IsolatedStorageException: Unable to create the store directory. (Exception from HRESULT: 0x80131468)]
Cassette.Web.ExceptionCachedManager.CreatePageAssetManager(HttpContextBase httpContext) +92
Cassette.Web.CassetteHttpModule.<Init>b__0(Object sender, EventArgs e) +173
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +80
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +266
The default behaviour of creating a single asset module for the entire application is really confusing people.
I can see "WTF?! Why is Cassette including all my files?!" becoming a common question :)
So perhaps the default mode of Cassette should treat each file as a separate module. Referencing would still work. So if a script references jquery.js then referencing that script in a page also brings in jquery.
We just need to add a ModulePerFile
implementation of IModuleSource
and use that as the default when no other module sources have been configured.
Thoughts?
Hello. Teleriks' asset manager provides for the adding of assets to specific groups. In this way I could define a group like "form" which might reference jquery validate, my validate extensions, other form stuff. Then on a page that contains a form I can just enable that group.
In this way all the possible assets and groups etc are always configured, usually in a single spot, then they are "turned on" when needed.
It would be nice if you could have a configuration setting to specify that the URLs generated from:
string DebugScriptUrl(Asset asset)
string ReleaseScriptUrl(Asset asset)
have a prefix such as http://static.myDomain.net/...........
rather than always being virtual paths (~/Scripts/) that get converted to app relative paths.
Cannot easily include your assembly in projects that are strongly named (digitally signed) because Cassette itself is not strongly named.
I would need to download the source code, sign it myself, and re-build.
An error occurs saying "js/app.js" cannot be found. However, if you create (or just leave) the "Scripts" directory and put "app.js" in it everything loads fine.
Support should be added for those that want to leverage directories for js files other than the "Scripts" directory.
I'm not sure why, because I can't find any error in my CSS files, but my page looks like shit when debug = false (and thus the CSS gets minified).
Is there any way to turn off minification for stylesheets (perhaps on a module-by-module basis)?
Also, do you have any advice or tools to detect CSS formatting errors that the eye (my eye at least) can't see? :)
Probably rename it to be IDirectory and tidy up the interface in general.
This will require a new pluggable module rendering system.
I would be cool to have /_assets
provide documentation and details about current asset module configuration.
Decide what the behavior should be!
IIS6 won't send the rewritten css image URLs to the Cassette handler.
Either document the need for a wildcard mapping in IIS6, or provide an option to rewrite URLs to application absolute instead.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.