ColdFusion application caches switch statement - caching

I'm not familiar with caching in coldfusion, but it seems it's doing somethnig it's not supposed to in my website.
I have only one index page, that uses a big switch statement to determin what cfm files to include, to build my website's pages. No everything works fine, I even have a default case that refers back to the homepage when trying to access a non-existing page.
When I create a new page and try to go to it but in the meantime forgetting I need to add a cfcase first, goes to the defaultcase. If I then create the needed cfcase, it should work, but it has cached the redirect of the last time, the path it followed in the switch/case, so I still get the defaultcase. Even if remove the defaulcase from the code, it still goes there.
Is there anyway to tell coldfusion to stop caching my switch/case. The rest of the content may be chached, no problem, just not the path of the switch/case..
edit 1
Here's my code:
<html>
<head>
</head>
<body>
<cfswitch expression="#attributes.fuseaction#">
<cfcase value="home">
<cfinclude template="dsp_home.cfm" />
</cfcase>
<cfcase value="admin">
<cfinclude template="admin/dsp_login.cfm" />
</cfcase>
<cfdefaultcase>
<cf_goto fuseaction="home">
</cfdefaultcase>
</cfswitch>
</body>
</html>
attributes.fuseaction is a variable that is stored in the url of the requested page, like so: http://www.domain.com/index.cfm/fuseaction/#switch/case-variable#.
cf_goto is a custom tag that gives a 301 code and redirects to the specified page where that variable is home.
When I do what I described above, the headers still give me the 301 error code and de redirect to the default case page. So I'm at a loss what it is that's being cached here.

CF doesn't cache switch/case logic, so it's a red herring to be looking at that to solve whatever your problem actually is.
Do you - by any chance - have "Trusted Cache" switched on in CFAdmin? If so, you'll need to clear it so your CFM files recompile when they're requested, and your changes will take effect.
Failing that: we need to see your code, as per Duncan's suggestion.

Related

Changing url link for page in processwire

I'm looking for a way to change the redirect for a page in processwire.
Logging in the admin back end I see this order page
Upon editing:
But the redirect url from header meta I guess still redirects to the previous link. I tried looking in the database and changed it there also but it still keeps it in settings somewhere.
Any ideas where this is?
Seems like you expect the page to redirect via a meta description tag. Meta description is for SEO, to tell search engines what the page is about. If your page has a meta redirect tag - which should look like
<meta http-equiv="refresh" content="0; url=http://example.com/">
it doesn't seem to be edititable via your CMS. Either change it directly in the templates, or add a field for this to the backend and add an output in the template.

How to clean browser cache with the help of the code

I've made a lot of changes in the front end part of the project. But for applying them all users should clear the browser cache. Is there any way for cleaning users browsers cache from programming side?
Yes, you need to version your static files. I use this trick:
<link href="/css/style.css?v=<?php echo filemtime($basepath."/css/style.css")?>" rel="stylesheet" type="text/css" />
Obviously that code will need adjustment, but you get the idea. It appends the file modification time as a version number on the file. So that every time it is changed (and only when it's changed) it completely busts the cache server and client side. Saves all those "I can't see any changes" calls from the clients! :)
Of course if you don't want to go the automatic route, you need only append the css (js etc) files with ?v=1.0 for example

How to give URL for Home page from Spring MVC on Heroku

I have looked and tried everywhere without success so posting this question.
Recently deployed a working Spring MVC app on Heroku platform, it was a pleasant experience for the most. How ever the spring url tag or even jstl core url tag are behaving differently on Heroku, than on my local tomacat server.
for example my links '>Sign in would be perfect resolves to http: //mydomain:port/context/signin on my local but after deploying the Heroku it would /signin as absolute path, so i quickly removed and it is working good.
However i have a home link on my nav bar that is '>Home if I remove the forward slash then the Home link is essentially point to what ever is my current url on address bar instead of context home.
Any suggestions ?
From experience what works best for me is not to hardcode your link with / on the left, but create this "root" variable on your jsp:
<c:set var="root" value="${pageContext.request.contextPath}"/>
Then in your jsp whenever you need reference root path:
<img src="${root}/resources/mycoolpic.png"/>
Other variation is you can use html <base..> tag to set where / refer to but this make your code more obscure and hard to understand. For example:
<base href="my-root">
<img src="/resources/mycoolpic.png"/>
Will actually resolve to /my-root/resources/mycoolpic.png
just after going through couple of other similar questions and answers, the below approach solved my problem on Heroku for Home page link.
created a <base/> element in <head> as below
<base href="${pageContext.request.scheme}://${pageContext.request.serverName}
:${pageContext.request.serverPort}${pageContext.request.contextPath}" />
then in jsp the code below started resolving correctly on Heroku
</s:url>'>Home
<s:url value="signin"></s:url>'>Sign in</a>
how ever for my local tomcat deployments to work i had to append an extra forward slash to the above
<base href="${pageContext.request.scheme}://${pageContext.request.serverName}
:${pageContext.request.serverPort}${pageContext.request.contextPath}/" />
since this code is only in my base template I guess I will have to live with this one file descrepency between my local and deployed versions
I would love to see any wholesome answers

Can I make my ajax website 'crawlable'?

I'm currently building a music based website and I want to build something like this template. It uses ajax and deep linking. (And it makes use of the History.js library - please notice how there's no '#' in the URLs.)
The reason I want to use these 'ajaxy' methods (or maybe use the template altogether) is so that when music is playing, it will remain un-interrupted as the user navigates the site.
My worry is that my site wont be crawlable by Google but I think I can modify code in the page source to fix that. If I look at the source code to the template, in the head I see
<meta name="description" content="">
<meta name="author" content="">
<meta name="keywords" content="">
Now if I add this to the head:
<meta name="fragment" content="!">
will that make the site crawlable? Is there other code I need to add on top of this? Or is it just not possible for this template?
I'm following this guide https://developers.google.com/webmasters/ajax-crawling/docs/getting-started, and I'm on step 3. I will of course have to complete the other steps but I don't know I'm heading in the right direction, or heading towards a dead end!
Any help would be very much appreciated. Many thanks in advance.
From what you said it sounds like your site updates the address bar with clean urls as you navigate via ajax. That's good. The next thing is you want to do is make sure those urls work. If you directly go to a url do you see the specific content it represents. And would a crawler also see the correct content without running javascript. Progressive enhancement works well for that. The final thing is you want to do is make sure bots can pick up those urls.
I've not played with the meta tag for ! But it looks like it is only for the home page and you still need to implement the escaped fragment page. Maybe it does support other pages but the article does not cover that.

How do I correctly ENABLE browser caching using codeigniter?

Every time I do I search on this I get information about how to disable the browser cache.
Never anything about enabling it.
How do I get the back button to use the cache and not regenerate the page?
As far as I know you can control to force a browser to reload the data by means of these meta tags:
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-control" content="no-cache">
<meta http-equiv="Expires" content="0">
but you cannot force it to read from cache. The browser itself will do that for you if you don't explicitly specify to ignore the cache, and the page data are in fact cached and not expired.
This does not depend on CodeIgniter because it's client-side, but you might want to use the meta() function included in CI's html helper, which will simply output the corresponding meta tag. e.g:
echo meta('Cache-control', 'no-cache', 'http-equiv');
would generate the second code line above.
Note:
The 1st meta tag is specified for http/1.0 while the 2nd one is for http/1.1 but both are used to allow backwards compatibility.
If you're using xhtml instead of html remember to close the meta tags with />
Browser caching has nothing to do with codeigniter. You can use html meta tags to instruct the browser specifically not to cache pages or you can set a cache expiry for an individual page like so:
<meta http-equiv="expires" content="Mon, 10 Dec 2001 00:00:00 GMT" />
You could use a bit of php to drop tomorrows date in there. The browser (depending on settings) will usually pull as much as it can from the cache automatically, including when clicking the back button - the cache for the back button will work the same as if you were coming in from any other link.
You could set expires headers through your htaccess using something like the following on an apache server (you would have to ask about how to do this on other server types) to tell the browser that is should cache certain types of content for a given periods of time:
ExpiresByType text/html "access plus 60 seconds"
This will tell the browser to store anything of mime type text/html for 60 seconds (this includes codeigniter output) BUT DONT DO THIS if your dealing with dynamic content It will stop any dynamic page content being loaded and will stop any changes to your content being loaded by returning visitors (Obviously this second part is not such an issue with a 60 second cache).
The key thing to realise is that Your page is not one thing, it's made up of lots of parts, some of these parts should be called from cache (js, css, images, etc.) some should not (often html will fall into this category).
The browser will automatically call all the parts of your page from the cache where the cache has not expired.
Usually you would use .htaccess (or similar method) to cache your css, images, etc. (using versioning in filenames to force a reload when they change).
You should also take advantage of server side caching - codeigniter does this for whole pages but I dont tend to find this very helpful for any kind of dynamic site so I would take a look at for using phil sturgeons partial caching library for ci if you are interested in ss caching:
https://github.com/philsturgeon/codeigniter-cache
This wont stop a request being sent to the server but will mean that request requires less processing and can be served as one or several pieces of static content.

Resources