Apply cache manifest only in production mode - asp.net-mvc

I've added a "cache.manifest" in my application (this works perfectly) and since then, it's very hard to debug since I must always clear the cache or modify the cache.manifest version.
I tryied to load the manifest with "HttpContext.Current.IsDebuggingEnabled" condition:
<!DOCTYPE HTML>
#if (HttpContext.Current.IsDebuggingEnabled)
{
<html>
}
else
{
<html manifest="/cache.manifest">
}
This doesn't works and Visual Studio gives me 3 errors:
The block is missing a closing } character
html element is not closed
Can't have more than 1 html element.
Does anyone have an idea ?
Thanks !

Based on the answer from "sav931", I finally found the solution:
<html #(HttpContext.Current.IsDebuggingEnabled ? "" : "manifest=cache.manifest" )>
No need to add an app setting key in the web.config, since there's already a function for that. (HttpContext.Current.IsDebuggingEnabled)
Also, I removed the manfest attribut completely when developping.

Try to add key in the web.config like:
<add key="devMode" value="true"/>
and now add this in your View:
<head #(Convert.ToBoolean(System.Web.Configuration.WebConfigurationManager.AppSettings["devMode"]) ? "manifest=/cache.manifest" : "manifest=devMode.manifest")>
by adding a manifest file name that not exist it will disable the cache...

Related

Changing dependency of WebSharper.JQueryUI to load jquery-ui.js locally

I'm writing on a WebSharper sitelet that uses the JQueryUI extension. The HTML generated by the WebSharper sitelet looks like this:
<html>
<head>
...
<script src="//code.jquery.com/ui/1.11.1/jquery-ui.js" ...></script>
I'm frequently without internet while developing, so I'd really like to serve jquery-ui.js off the development server instead. That is, I'd much rather have this:
<html>
<head>
...
<script src="/Scripts/jquery-ui.js" ...></script>
The docs say this should be possible by setting an appropriate appSetting in Web.config, but no value I set for the keys listed in the docs seem to have any effect on the output.
I'm using (NuGet versions) WebSharper 3.0.54.140 and WebSharper.JQueryUI 3.0.45.241.
How do I force WebSharper to output a link to a resource local to the server?
Indeed there is an error in the documentation. The key to use is the fully qualified name of the resource type, so for WebSharper.JQueryUI it should be:
<appSettings>
<add key="WebSharper.JQueryUI.Dependencies+JQueryUIJs" value="/Scripts/jquery-ui.js" />
<add key="WebSharper.JQueryUI.Dependencies+JQueryUICss" value="/Content/jquery-ui.css" />
</appSettings>
Edit: just fixed the documentation.

Grails: links for text files

In my Grails app I need to serve links to actual text (*.txt) files. If the user clicks the link, they should view the text file as plaintext inside their browser:
MyFiles.groovy controller:
==========================
class MyFiles {
def index() {
render(view: "myfiles")
}
}
myfiles.gsp:
============
<!DOCTYPE html>
<html>
<head>
<!-- Omitted for brevity -->
</head>
<body>
Click me to view a file
</body>
</html>
My questions:
Where should I place myfile01.txt inside the Grails project? Directly inside web-app? Inside a web-app/myfiles dir? Inside WEB-INF?; and
What should the link be in the GSP, such that Grails correctly resolves correctly and displays the file? I don't see anything under g:links that stands out as an obvious choice.
I'd recommend creating another folder where you have images/css.
<a href='<g:resource dir="somedirectory" file=myfiles01.txt" absolute="true" />'>my file</a>

"Object reference not set to an object" when starting out with Cassette

I'm trying to get started with Cassette via NuGet. I'm having issues with it in my app so I rolled back and tried it in a new empty ASP.NET MVC 3 web application.
However, the problem persists. Following the documentation page "Easy to use", I simply can't get it to work. Here's the exception along with a bit of the stack:
"Object reference not set to an instance of an object."
[NullReferenceException: Object reference not set to an instance of an object.]
Cassette.CassetteApplicationContainer.get_Application() +6
Cassette.Views.Bundles.Reference(String assetPathOrBundlePathOrUrl, String pageLocation) +14
ASP._Page_Views_Shared__Layout_cshtml.Execute() in d:\Dave\Documents\Visual Studio 2010\Projects\CasetteTest\Views\Shared\_Layout.cshtml:2
System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +207
I simply followed the two steps in the documentation and this is what I get. What am I doing wrong?
This is what my _Layout.cshtml file looks like:
#{
Bundles.Reference("Scripts/jquery-1.5.1.min.js");
Bundles.Reference("Scripts/modernizr-1.7.min.js");
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>#ViewBag.Title</title>
<link href="#Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
</head>
<body>
#RenderBody()
#Bundles.RenderScripts();
</body>
</html>
I figured it out.
I included the Cassette.Views package which does not create a default CassetteConfiguration.cs file that bundles each script and each css file in its own bundle. That's what triggered the NullReferenceException. In order to get it to work, you'll need to add the Cassette.Web package instead. In my defense, the package descriptions in the NuGet gallery are not clear and one is led to believe that the Views package is required for MVC and the other for WebForms.
The next problem was that I referenced the minified '.min.js' scripts which are not picked up by the bundler (it seems).
Cannot reproduce the issue.
4 simple steps allowed me to get a fully working prototype in less than 30 seconds:
Create a new ASP.NET MVC 3 project in Visual Studio
Install-Package Cassette.Web
Index.cshtml:
#using Cassette.Web
#{
Bundles.Reference("~/Scripts/jquery-1.5.1.js");
Bundles.Reference("~/Scripts/jquery-ui-1.8.11.js");
Bundles.Reference("~/Content/site.css");
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<title>Web App</title>
#Bundles.RenderStylesheets()
</head>
<body>
<div>Hello World</div>
#Bundles.RenderScripts()
</body>
</html>
Hit Ctrl+F5 to run the project

classic ASP with non-english languages special characters as boxes

I am currently working on Classic ASP for one of my project. For non English languages I am getting boxes instead of special characters. I am rendering using UTF-8 but sometimes the characters goes to boxes. It comes back normal when I click refresh sometimes.
I followed all the steps below but i still get this problem
XML:
<xml version="1.0" encoding="UTF-8">
HTML:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
content-type: text/html; charset=utf-8
Am I missing anything here? Thanks.
Add this to your page:
Response.CodePage = 65001
Response.CharSet = "utf-8"
It should display all correctly now.
Hope that helps
It's amazing BUT nobody gives a complete answer on what to do this PROPERLY... I hope this help somebody like me, because it was so hard to find the whole picture...
---------------- PREVIOUS CONSIDERATIONS --------------
FIRST, make sure IIS IS NOT replacing the Code Page... Go to IIS, click the Website, open ASP module, on Behavior it should be >> Code Page = 0
SECOND, The file itself should be checked, YES! the file... open your file explorer on windows (my computer), go to the folder where the files of your website are, take for example "default.asp", right click >> open with >> notepad THEN click on File >> Save As... IN THE DIALOG at the bottom says "Encoding", make sure it has UTF-8, otherwise you will have to add the
<meta http-equiv="content-type" content="text/html; charset=UTF-8"> in every page (including server side includes), which is not correct.
---------------- CORRECT STRUCTURE OF THE PAGE --------------
<%#LANGUAGE="VBSCRIPT" CODEPAGE="65001"%><%
Response.AddHeader "Content-Type", "text/html;charset=utf-8"
%><!-- #include virtual="/conexion.asp" -->
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="utf-8">
</head>
<body>
áéíóú
</body>
</html>
It should work fine now with QueryStrings, Database and regular HTML... uffff

$sf_response->addStyleSheet() dosen't work in SF 1.4?

Does anyone know how to add stylesheets in a template with Symfony 1.4 ?
I have tried everything I can think of, from modifying frontend/config/view.yml to modifying the template itself - bothing works.
I have seen from my searches, that other people have had the same problem. There seems to be a clash of sorts between using include_stylesheets and use_stylesheets - however this is not documented anywhere AFAIK.
Edit:
Ok I think I got it now. You should add include_stylesheets() into the head section of your layout file:
<html>
<head>
<title>This is the title</title>
<?php include_stylesheets() ?>
</head>
<body>
<!-- ... -->
Then in your template file, you use use_stylesheet() to add a particular stylesheet for this template:
<?php use_stylesheet('/path/to/stylesheet.css') ?>
From the API documentation:
include_stylesheets()
Prints <link> tags for all stylesheets configured in view.yml or added to the response object.
use_stylesheet()
Adds a stylesheet to the response object.
Same for Javascript.
According to the API documentation it should still work in 1.4, sfWebResponse still has this method:
addStylesheet ($file, $position, $options)
$file The stylesheet file
$position Position
$options Stylesheet options
Adds a stylesheet to the current web response.
At least the method exists.
What exactly is the problem? Do you get an error if you want to call that method or is the stylesheet just not added?
http://www.symfony-project.org/tutorial/1_4/en/upgrade#removal_of_the_common_filter
As of 1.4 your javascripts and stylesheets are no longer automatically injected into your head tag. Instead, you need to include the following in your layout where you'd like them to be placed:
<?php include_javascripts() ?>
<?php include_stylesheets() ?>
and just in case your post title wasn't a typo you'll want to use addStylesheet('...') off of the response:
$sf_response->addStylesheet('main');
$sf_context->getResponse()->addStylesheet('style.css')
$sf_context->getResponse()->addJavascript('script.js')

Resources