is Scripts/Home a reserved name for bundle? - asp.net

If i do
//BundleConfig.cs
bundles.Add(new ScriptBundle("~/Scripts/Home").Include("~/Scripts/Home/Home.js"));
//index.cstml
#section scripts
{
#Scripts.Render("~/Scripts/Home")
}
then the script is not going to get rendered in release mode, it works fine in debug mode without
BundleTable.EnableOptimizations = true;
but if i do
//BundleConfig.cs
bundles.Add(new ScriptBundle("~/bundles/Home").Include("~/Scripts/Home/Home.js"));
//index.cstml
#section scripts
{
#Scripts.Render("~/bundles/Home")
}
then it works fine in both debug and release mode.
Is Scripts/Home a reserved name or something?
Note: I do not have anything else named ~/Scripts/Home in BundleConfig.cs

Not Scripts/Home in particular but it must be a valid bundle name, or path to an actual file.
For example if you were to add the following to your View without adding the appropriate bundle name it would actually render the script directly from disk to the browser. (yay)
#Scripts.Render("~/scripts/jquery-1.8.2.js")
But any reference to a non existent file or bundle name would cause an error, like these:
#Scripts.Render("~/scripts/jquery/*.*") -- error, no wildcards either
#Scripts.Render("~/non-existant-directory-or-bundle-name") -- error
#Scripts.Render("~/scripts/no-such-file.js") -- error

No, however the bundle name (~/Scripts/Home) cannot match either an existing folder or file.
For this reason, I leave my scripts in ~/Scripts/... but name the bundles ~/js/....

Related

Meteor's Iron.Router adding an extra "/" to route names and not allowing home route

I am having a problem getting iron-router to correctly store and access routes. It appears that Iron.Router is adding an extra slash (/) before the route names, not ignoring case for template names, and not creating a default route.
I am adding Iron.Router to a simple testing app I have that I have split up for separate pages, but I cannot get any page to work as documented either with the map() or route() functions. I have spent hours trying options and searching and I seem to be the only one who ever had this problem. So I set up a minimum project to test. I created a new meteor project, removed the files, then copied basic.js and basic.html from https://github.com/EventedMind/iron-router/tree/devel/examples. All this example does is show three pages when you click between them. I then…
vagrant#precise32:/vagrant/test$ meteor add iron:router
vagrant#precise32:/vagrant/test$ meteor update
This project is already at Meteor 0.9.3.1, the latest release.
Your packages are at their latest compatible versions.
vagrant#precise32:/vagrant/test$ npm version
{ http_parser: '1.0',
node: '0.10.32',
v8: '3.14.5.9',
ares: '1.9.0-DEV',
uv: '0.10.28',
zlib: '1.2.3',
modules: '11',
openssl: '1.0.1i',
npm: '2.1.2' }
vagrant#precise32:/vagrant/test$ ls
basic.html basic.js.
vagrant#precise32:/vagrant/test$ meteor
It started successfully, but threw a JS error on in Chrome (or FF). Exception from Tracker recompute function: Error: Couldn't find a template named "/" or "". Are you sure you defined it? Well yes, I did. Giving the route a blank name generates no error and no home page. So next I tried adding “/one” on the URL. I then get the JS error Error: Oh no! No route found for path: "/one". Next I changed the parameter in my route() call from “/one” to “one” and got this error: Error: Couldn't find a template named “one” or “one”. Are you sure you defined it? I then tried adding explicit code for route “one”: “function() { this.render(“Home”)} to reference the template “Home” using the same case. I got the exact same error message as without the explicit code. The only way I could get page one to display was to changed the name from “One” to “one” in the HTML. I couldn't get the default page to display at all.
When poking around (using Chrome’s console) in some internal variables, I found Router.routes, which has this highly suspicious content:
>Router.routes.forEach( function(v) {console.info("name = '%s', originalPath = '%s', re = '%s'",v.name,v.originalPath,v.re)})
2014-10-04 16:10:07.756 name = '/', originalPath = '//', re = '/^//?$/i'
2014-10-04 16:10:07.757 name = '/one', originalPath = '//one', re = '/^//one/?$/i'
2014-10-04 16:10:07.758 name = '/two', originalPath = '//two', re = '/^//two/?$/i'
(If I name the path "one", then the route will show 'one' as the name, and '/one' as the originalPath.
Details: This is a brand new folder with only these two files in it (and the hidden .meteor folder). The only package added was “iron:router”. I did a meteor update just before my last round of testing (one hour ago). I have set no environment variables. I have the latest version of Chrome & FireFox. I am using VirtualBox via Vagrant from Window 8 with 12G memory. Every other Meteor project I’ve done so far works, (well except for some trying to use jQuery).
If this was a bug in Iron:router, someone else would have noticed, but there are no more settings I can find anywhere that could be adding or subtracting the extra “/” in Iron-Router. Anyone have any ideas of what I need to look for for making a vanilla Iron-Router work with a vanilla Meteor project on my machine?
You are really out of luck because your problem is very simple : you are running examples which are intended to work with the LATEST iron:router#1.0.0-pre3, but your iron:router version is most likely 0.9.4.
Try this :
meteor remove iron:router
meteor add iron:router#1.0.0-pre3
If you want a little more insight, routes used to be declared with name first and path as an option, this is now the contrary.
0.9.4
Router.map(function(){
this.route("home",{
path:"/"
});
});
1.0.0-pre3
Router.route("/",{
name:"home"
});

Laravel/blade caching css files

I am working on Nginx server, with PHP-FPM. I installed Laravel 4.1 and bootstrap v3.1.1., and here is the problem. For the last 30 minutes, I have been trying to change a css rule that I first declared to check boostrap.
.jumbotron{
background: red;
}
The first time it worked. The jumbotron container was red. So, I removed that css value and started working, but still no matter which browse I use, the container is red. I even checked the css file through the Google Chromes inspection tool, and it is showing me that first value when jumbotron had a background:red. I deleted the css file and renamed it and add new styles, I configured chrome not to cache pages. But Still the same value. I'm convinced now, that Laravel has kept a cache of the first style declaration.
Is there any way to disable this at all?
General explanation
When you access a Laravel Blade view, it will generate it to a temporary file so it doesn't have to process the Blade syntax every time you access to a view. These files are stored in app/storage/view with a filename that is the MD5 hash of the file path.
Usually when you change a view, Laravel regenerate these files automatically at the next view access and everything goes on. This is done by comparing the modification times of the generated file and the view's source file through the filemtime() function. Probably in your case there was a problem and the temporary file wasn't regenerated. In this case, you have to delete these files, so they can be regenerated. It doesn't harm anything, because they are autogenerated from your views and can be regenerated anytime. They are only for cache purposes.
Normally, they should be refreshed automatically, but you can delete these files anytime if they get stuck and you have problems like these, but as I said these should be just rare exceptions.
Code break down
All the following codes are from laravel/framerok/src/Illuminate/View/. I added some extra comments to the originals.
Get view
Starting from Engines/CompilerEngine.php we have the main code we need to understand the mechanics.
public function get($path, array $data = array())
{
// Push the path to the stack of the last compiled templates.
$this->lastCompiled[] = $path;
// If this given view has expired, which means it has simply been edited since
// it was last compiled, we will re-compile the views so we can evaluate a
// fresh copy of the view. We'll pass the compiler the path of the view.
if ($this->compiler->isExpired($path))
{
$this->compiler->compile($path);
}
// Return the MD5 hash of the path concatenated
// to the app's view storage folder path.
$compiled = $this->compiler->getCompiledPath($path);
// Once we have the path to the compiled file, we will evaluate the paths with
// typical PHP just like any other templates. We also keep a stack of views
// which have been rendered for right exception messages to be generated.
$results = $this->evaluatePath($compiled, $data);
// Remove last compiled path.
array_pop($this->lastCompiled);
return $results;
}
Check if regeneration required
This will be done in Compilers/Compiler.php. This is an important function. Depending on the result it will be decided whether the view should be recompiled. If this returns false instead of true that can be a reason for views not being regenerated.
public function isExpired($path)
{
$compiled = $this->getCompiledPath($path);
// If the compiled file doesn't exist we will indicate that the view is expired
// so that it can be re-compiled. Else, we will verify the last modification
// of the views is less than the modification times of the compiled views.
if ( ! $this->cachePath || ! $this->files->exists($compiled))
{
return true;
}
$lastModified = $this->files->lastModified($path);
return $lastModified >= $this->files->lastModified($compiled);
}
Regenerate view
If the view is expired it will be regenerated. In Compilers\BladeCompiler.php we see that the compiler will loop through all Blade keywords and finally give back a string that contains the compiled PHP code. Then it will check if the view storage path is set and save the file there with a filename that is the MD5 hash of the view's filename.
public function compile($path)
{
$contents = $this->compileString($this->files->get($path));
if ( ! is_null($this->cachePath))
{
$this->files->put($this->getCompiledPath($path), $contents);
}
}
Evaluate
Finally in Engines/PhpEngine.php the view is evaluated. It imports the data passed to the view with extract() and include the file with the passed path in a try and catch all exceptions with handleViewException() that throws the exception again. There are some output buffering too.
Same issue here. I am using VirtualBox with Shared Folders pointing to my document root.
This pointed me in the right direction:
https://stackoverflow.com/a/26583609/1036602
Which led me to this:
http://www.danhart.co.uk/blog/vagrant-virtualbox-modified-files-not-updating-via-nginx-apache
and this:
https://forums.virtualbox.org/viewtopic.php?f=1&t=24905
If you're mounting your local dev root via vboxsf Shared Folders, set EnableSendFile Off in your apache2.conf (or sendfile off if using Nginx).
For what it's worth and because this answer came up first in my google search...
I had the same problem. The CSS and JS files wouldn't update. Deleting the cache files didn't work. The timestamps were not the problem. The only way I could update them was to change the filename, load it directly to get the 404 error, and then change the name back to the original name.
In the end the problem was not related to Laravel or the browser cache at all. The problem was due to NginX using sendfile which doesn't work with remote file systems. In my case, I was using VirtualBox for the OS and the remote file system was vboxsf through Guest Additions.
I hope this saves someone else some time.
In Laravel 5.8+ you can use so:
The version method will automatically append a unique hash to the filenames of all compiled files, allowing for more convenient cache busting:
mix.js('resources/js/app.js', 'public/js').version();
After generating the versioned file, you won't know the exact file name. So, you should use Laravel's global mix function within your views to load the appropriately hashed asset. The mix function will automatically determine the current name of the hashed file:
<script src="{{ mix('/js/app.js') }}"></script>
full document: https://laravel.com/docs/5.8/mix

ASP.NET bundling and minification not producing query string params

I've been using ASP.NET bundling and minification with the nugget package Microsoft.AspNet.Web.Optimization.
I noticed yesterday that the majority of my bundle files no longer have the v query string parameter to the exception of one of them:
/Sgc.Web/bundles/css/JQueryUI
/Sgc.Web/bundles/css/DefaultPage
/Sgc.Web/bundles/js/Menu
/Sgc.Web/bundles/js/DefaultPage
/Sgc.Web/bundles/js/ReportOutputs
/Sgc.Web/bundles/js/UnderscoreBackbone?v=4YsZ6DBVserabs64GE87Ua4d51aeg0D1wXHWNe3E6NU1
The JS bundle that still has the query string always keeps on producing different v param values after I do changes on it (as expected). However the remaining bundles (either css or js) when I make changes on their css or js files they do incorporate those changes but do not produce a v param value any more.
The C# code to perform the bundling:
// -- create and add CSS bundles without minification
BundleTable.EnableOptimizations = true;
bundles.Add(new Bundle("~/bundles/css/JQueryUI").Include(
"~/Styles/Gui/jquery-ui-1.10.4-custom.css",
"~/Styles/Gui/jquery-ui-custom.css",
"~/Styles/Gui/jquery.ui.combogrid.css"));
bundles.Add(new Bundle("~/bundles/css/DefaultPage").Include(
"~/Styles/Default.css",
"~/Content/toastr.min.css"));
// -- create and add JS bundles without minification
bundles.Add(new Bundle("~/bundles/js/DefaultPage").Include(
"~/Scripts/Defaults.js",
"~/Scripts/toastr.min.js"));
bundles.Add(new Bundle("~/bundles/js/Menu").Include(
"~/Scripts/Gui/Menus/SuperFish/jquery.hoverIntent.r7.min.js",
"~/Scripts/Gui/Menus/SuperFish/superfish1_7_4.min.js",
"~/Scripts/Gui/Menus/SuperFish/factory.js"));
bundles.Add(new Bundle("~/bundles/js/UnderscoreBackbone").Include(
"~/Scripts/underscore.min.js",
"~/Scripts/backbone.min.js"));
bundles.Add(new Bundle("~/bundles/js/ReportOutputs").Include(
"~/Scripts/Gui/jquery-visibility.js",
"~/Scripts/UserControls/ReportOutputs.js"));
//-- if in Release mode, then minify all the bundles
if (!System.Web.HttpContext.Current.IsDebuggingEnabled)
{
CssMinify cssMinify = new CssMinify();
JsMinify jsMinify = new JsMinify();
foreach (Bundle bundle in bundles)
{
if (bundle.Path.Contains("/js"))
{
bundle.Transforms.Add(jsMinify);
}
else
{
bundle.Transforms.Add(cssMinify);
}
}
As can be seen from above I'm building the bundle with the Bundle super class instead of the StyleBundle or ScriptBundle sub classes. However I also tried to make bundles with these 2 subclasses and the result was the same: all bundles still didn't had v param to the exception of the UnderscoreBackbone bundle. As far as I know there is no difference in the way the UnderscoreBackbone bundle is being made and the remaining bundles.
I'm using,
Windows 8.1
VS Premium 2013 with Update 1
Microsoft.AspNet.Web.Optimization 1.1.3
WebGrease 1.6.0
Microsoft.Web.Infrastructure 1.0.0.0
Json.NET (Newtonsoft.Json) 6.0.1
ANTLRv3 3.5.0.2
Does anyone ever faced this kind of problem before or any hint as to where can I look for a solution to it ?
Thanks in advance,
MggLp
Sometimes, in views, we might be doing something like -
Scripts.Render("/bundles/js/Default‌​Page")
but the correct syntax to get hash -
Scripts.Render("~/bundles/js/Default‌​Page").
It might be the matter of absolute and relative path.
Using ~ we can get the querystring for the bundled files.

how to properly register nginx header filter?

I'm writing an nginx module.
From looking at other examples I'm registering my header filter in my modules postconfiguration hook:
static ngx_int_t
mod_py_postconfig(ngx_conf_t *cf)
{
ngx_http_next_header_filter = ngx_http_top_header_filter;
ngx_http_top_header_filter = mod_py_headers_filter;
return NGX_OK;
}
But the handler is never called. I've set a breakpoint in gdb on ngx_http_top_header_filter change and it seems my module's postconfig is called first, but then runs postconfig of the ngx_http_write_filter_module which overrides ngx_http_top_header_filter w/o storing the old value:
static ngx_int_t
ngx_http_write_filter_init(ngx_conf_t *cf)
{
ngx_http_top_body_filter = ngx_http_write_filter;
return NGX_OK;
}
it seems like it is designed to be the very last on called, so how come my module's postconfig is called first?
From what I can see the order of modules is set in objs/ngx_modules.c
I was able to fix the problem by manually reordering the modules there so that my module comes after ngx_http_header_filter_module, but this feels like an ugly hack, and also makes it hard to automate build process as ./configure overwrites this file each time.
OK, so I figured it out myself. Documenting it here in case anyone else will need it.
I was adding my module to the wrong list. The nginx module is configured through a 'config' file insed module's directory. My had the following line in it:
HTTP_MODULES="$HTTP_MODULES ngx_http_my_module_name"
I searched for HTTP_MODULES usage and found nginx/auto/modules script which actually builds ngx_modules.c file. It turns out there are several possible module lists used by nginx/auto/modules. I needed to add my module to the HTTP_AUX_FILTER_MODULES list like so:
HTTP_AUX_FILTER_MODULES="$HTTP_AUX_FILTER_MODULES ngx_http_my_module_name"
This placed my module at the right place just after HTTP_HEADERS_FILTER_MODULE and fixed the problem.

Subfolders in App_GlobalResources (ASP.NET)

Is it possible to put resource files (.resx) within subfolders inside App_GlobalResources?
For example:
/App_GlobalResources/someresources/myfile.resx
/App_GlobalResources/someresources/myfile.fr-fr.resx
/App_GlobalResources/othereresources/otherfile.resx
/App_GlobalResources/othereresources/otherfile.fr-fr.resx
Or, are all the .resx files placed directly inside App_GlobalResources?
If it is possible to use subfolders, how do you programmatically access resources within subfolders?
Technically, yes it is possible but there are some pitfalls. First, let me show you an example. Suppose my App_GlobalResources folder looks like so:
/App_GlobalResources
/Test
TestSubresource.resx
TestResource.resx
Each resource file has a single entry called "TestString". I added each resource file using the Visual Studio menu so it created a class for me. By default, all classes added to the App_GlobalResources folder will have the same namespace of Resource. So, if I want to use the class generator and I want Test in the namespace, I need to go into the TestSubresource.Designer.cs file and manually change the namespace. Once I do that, I can do the following:
var rootResource = Resources.TestResource.TestString;
var subResource = Resources.Test.TestSubResource.TestString;
I can also reference them using GetGlobalResourceObject:
var rootResource = GetGlobalResourceObject( "TestResource", "TestString" );
var subResource1 = GetGlobalResourceObject( "TestSubresource", "TestString" );
Notice that I still use the "TestSubresource" as the means to reference the resources in that file even though it is in a subfolder. Now, one of the catches, is that all the files must be unique across all folders in App_GlobalResources or your project will throw a runtime error. If I add a resource named "TestResource.resx" to /Test, it will throw the following runtime error:
The resource file '/App_GlobalResources/TestResource.resx' cannot be
used, as it conflicts with another file with the same name.).
This is true even if I change the namespace on the new resource.
So, in conclusion, yes it is possible, but you increase the odds of getting a runtime error because of two identically named resource files in different parts of the App_GlobalResources folder structure which is allowed by the file system but not by .NET.
It's possible. At least, I managed to do it.
Within a web site I added the App_GlobalResources folder. Inside it I created another folder "MyFolder" and placed MyResource.resx file inside. Resx file contained one pair MyKey1 - MyValue1.
Using the GetResource method of the following class I successfully extracted "MyValue1" for name="MyKey1"
static class Class1 {
static Assembly FindGlobalResAssembly() {
foreach(Assembly asm in AppDomain.CurrentDomain.GetAssemblies()) {
if(asm.FullName.StartsWith("App_GlobalResources."))
return asm;
}
return null;
}
public static object GetResource(string name) {
Assembly asm = FindGlobalResAssembly();
if(asm == null)
return null;
return new ResourceManager("Resources.MyResource", asm).GetObject(name);
}
}
This approach works in Medium trust also.
It seems that folders make no difference when accessing resources from code.

Resources