我有一个应用程序,还需要使其脱机使用。与在服务器上使用Javascript / Jquery在客户端上构建动态内容相比,我没有问题,但是我对基本页面布局感到困惑。
现在,我的server-only
页面的结构如下(我使用的是Coldfusion
):
<cfsavecontent variable="renderedResults">
<!--- Doctype --->
<cfinclude template="../templates/tmp_pagetop.cfm">
<cfoutput><head></cfoutput>
<cfif NOT isAjaxRequest()>
<!--- page header with all meta/js/css/icons... --->
<cfinclude template="../templates/tmp_pageheader.cfm">
</cfif>
<cfoutput>
<title>#variables.title# | #tx_select_title#</title>
</head>
<body>
// page
</body>
</html>
</cfoutput>
</cfsavecontent>
<!--- COMPRESS --->
<cfscript>
compressedHTML = reReplace(renderedResults, "\>\s+\<", "> <", "ALL");
compressedHTML = reReplace(compressedHTML, "\s{2,}", chr(13), "ALL");
compressedHTML = reReplace(compressedHTML, "\s{2,}", chr(09), "ALL");
variables.alredayBinary = "false";
</cfscript>
<!--- GZIP --->
<!--- SET HEADER --->
<!--- SEND BACK --->
我正在使用
Jquery Mobile
,当通过Ajax请求后续页面时,该页面将使用完整的head
加载第一页,然后再也不使用标题。因此,我正在检查是否通过Ajax请求了该页面,如果这样,我将在后续的页面请求上跳过向客户端发送8k header 的过程,因为JQM并未使用它们。另外,我的 header 模板包括很多条件内容,如下所示:
<cfif structKeyExists(cgi, "HTTP_USER_AGENT" ) AND findNoCase("facebook", cgi.http_user_agent) NEQ 0>
<cfoutput>
<meta property="og:title" content="#variables.title#"/>
<meta property="og:type" content="website"/>
<meta property="og:url" content="#variables.base#" />
<meta property="og:site_name" content="#variables.user_firma#"/>
<meta property="og:description" content="#variables.user_fbds#"/>
<meta property="fb:admins" content="#variables.user_fbadmin#" >
</cfoutput>
</cfif>
因此,当Facebook请求页面时,我仅包括Facebook Open Graph元。这样,如果Google要求,页面就会通过W3C验证。
现在挑战...如何使此静态和离线可用。
我已经考虑了一段时间,但并没有真正提出好的解决方案。如果我
每页请求
用法)=离线页面将被缓存,用户将
从缓存中“卡住”该版本,即使他在线也是如此。
我敢肯定,我不可能拥有全部,但是我想知道可以采用哪种方法来做到最好。
感谢您的投入!
最佳答案
您可以设置 session 变量以表示已加载 header 。然后,在每个页面上检查该变量,如果存在,则仅显示内容;如果不存在,请显示标题和内容。