Fossil SCM

Enable cache of the CSS style sheet.

drh 2025-09-16 10:47 trunk
Commit 0c1de587f974534c1b9bb348eb72a6d5f0322bd71402cf30545a33476e76e75e
1 file changed +12 -2
+12 -2
--- src/style.c
+++ src/style.c
@@ -1279,15 +1279,24 @@
12791279
** that the style sheet is cacheable.
12801280
*/
12811281
void page_style_css(void){
12821282
Blob css = empty_blob;
12831283
int i;
1284
- const char * zDefaults;
1284
+ const char *zDefaults;
12851285
const char *zSkin;
1286
-
1286
+ const char *zRequestUri = P("REQUEST_URI");
1287
+ const char *zScriptName = P("SCRIPT_NAME");
1288
+ const char *zKey = 0;
12871289
cgi_set_content_type("text/css");
12881290
etag_check(0, 0);
1291
+ if( zRequestUri && zScriptName && strlen(zScriptName)<strlen(zRequestUri) ){
1292
+ zKey = zRequestUri + strlen(zScriptName);
1293
+ }
1294
+ if( zKey && cache_read(cgi_output_blob(), zKey) ){
1295
+ g.isConst = 1;
1296
+ return;
1297
+ }
12891298
/* Emit all default rules... */
12901299
zDefaults = (const char*)builtin_file("default.css", &i);
12911300
blob_append(&css, zDefaults, i);
12921301
/* Page-specific CSS, if any... */
12931302
page_style_css_append_page_style(&css);
@@ -1306,10 +1315,11 @@
13061315
Th_Store("secureurl", fossil_wants_https(1)? g.zHttpsURL: g.zBaseURL);
13071316
Th_Store("home", g.zTop);
13081317
image_url_var("logo");
13091318
image_url_var("background");
13101319
Th_Render(blob_str(&css));
1320
+ if( zKey ) cache_write(cgi_output_blob(), zKey);
13111321
blob_reset(&css);
13121322
13131323
/* Tell CGI that the content returned by this page is considered cacheable */
13141324
g.isConst = 1;
13151325
}
13161326
--- src/style.c
+++ src/style.c
@@ -1279,15 +1279,24 @@
1279 ** that the style sheet is cacheable.
1280 */
1281 void page_style_css(void){
1282 Blob css = empty_blob;
1283 int i;
1284 const char * zDefaults;
1285 const char *zSkin;
1286
 
 
1287 cgi_set_content_type("text/css");
1288 etag_check(0, 0);
 
 
 
 
 
 
 
1289 /* Emit all default rules... */
1290 zDefaults = (const char*)builtin_file("default.css", &i);
1291 blob_append(&css, zDefaults, i);
1292 /* Page-specific CSS, if any... */
1293 page_style_css_append_page_style(&css);
@@ -1306,10 +1315,11 @@
1306 Th_Store("secureurl", fossil_wants_https(1)? g.zHttpsURL: g.zBaseURL);
1307 Th_Store("home", g.zTop);
1308 image_url_var("logo");
1309 image_url_var("background");
1310 Th_Render(blob_str(&css));
 
1311 blob_reset(&css);
1312
1313 /* Tell CGI that the content returned by this page is considered cacheable */
1314 g.isConst = 1;
1315 }
1316
--- src/style.c
+++ src/style.c
@@ -1279,15 +1279,24 @@
1279 ** that the style sheet is cacheable.
1280 */
1281 void page_style_css(void){
1282 Blob css = empty_blob;
1283 int i;
1284 const char *zDefaults;
1285 const char *zSkin;
1286 const char *zRequestUri = P("REQUEST_URI");
1287 const char *zScriptName = P("SCRIPT_NAME");
1288 const char *zKey = 0;
1289 cgi_set_content_type("text/css");
1290 etag_check(0, 0);
1291 if( zRequestUri && zScriptName && strlen(zScriptName)<strlen(zRequestUri) ){
1292 zKey = zRequestUri + strlen(zScriptName);
1293 }
1294 if( zKey && cache_read(cgi_output_blob(), zKey) ){
1295 g.isConst = 1;
1296 return;
1297 }
1298 /* Emit all default rules... */
1299 zDefaults = (const char*)builtin_file("default.css", &i);
1300 blob_append(&css, zDefaults, i);
1301 /* Page-specific CSS, if any... */
1302 page_style_css_append_page_style(&css);
@@ -1306,10 +1315,11 @@
1315 Th_Store("secureurl", fossil_wants_https(1)? g.zHttpsURL: g.zBaseURL);
1316 Th_Store("home", g.zTop);
1317 image_url_var("logo");
1318 image_url_var("background");
1319 Th_Render(blob_str(&css));
1320 if( zKey ) cache_write(cgi_output_blob(), zKey);
1321 blob_reset(&css);
1322
1323 /* Tell CGI that the content returned by this page is considered cacheable */
1324 g.isConst = 1;
1325 }
1326

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button