Comments (19)
Hi, please try with below option
app.use('/', expressStaticGzip(path.join(__dirname,'include_public')));
from express-static-gzip.
tried it - I get "Cannot GET /"
and I had to add require('path')
from express-static-gzip.
I also have tried the following suggestion from StackOverflow
app.get('*.css', function(req, res, next) {
req.url = req.url + '.gz';
res.set('Content-Encoding', 'gzip');
res.set('Content-Type', 'text/css');
next();
});
with no luck
from express-static-gzip.
I would have suggested something like @ramspassion did, as your initial setup seemed to have same issue related to your url or directory setup. Could you please provide more information about the url that is used in the browser to request that css file and the general directory setup?
[Edit:] You might also want to check if there is any other route setup for express that might overwrite the request for the css file, as express executes the first match and not the most specific match, some might expect.
from express-static-gzip.
this is the following structure right under include_public, which is included in app as static, so /bootstrap.css - the url of the page is mydomain.com/
─ bootstrap.bundle.min.js.save
├── bootstrap.css.gz
├── bootstrap.css.save
├── images
│ ├── border.png
│ ├── controls.png
│ ├── error.png
│ ├── loading_background.png
│ ├── loading.gif
│ ├── message.png
│ ├── overlay.png
│ ├── success.png
│ ├── ui-bg_diagonals-small_25_c5ddfc_40x40.png
│ ├── ui-bg_diagonals-thick_20_e69700_40x40.png
│ ├── ui-bg_diagonals-thick_22_1484e6_40x40.png
│ ├── ui-bg_diagonals-thick_26_2293f7_40x40.png
│ ├── ui-bg_highlight-soft_100_f9f9f9_1x100.png
│ ├── ui-bg_inset-hard_100_eeeeee_1x100.png
│ ├── ui-icons_001f3f_256x240.png
│ ├── ui-icons_0a82eb_256x240.png
│ ├── ui-icons_0b54d5_256x240.png
│ ├── ui-icons_444444_256x240.png
│ ├── ui-icons_555555_256x240.png
│ ├── ui-icons_5fa5e3_256x240.png
│ ├── ui-icons_777777_256x240.png
│ ├── ui-icons_cc0000_256x240.png
│ ├── ui-icons_fcdd4a_256x240.png
│ └── ui-icons_ffffff_256x240.png
├── jquery-3.3.1.min.js
├── js
│ ├── bootstrap.bundle.min.js
│ ├── index.js
│ ├── jquery.min.js
│ ├── jquery.tinymce.js
│ ├── jquery.tinymce.min.js
│ ├── langs
│ ├── plugins
│ ├── skins
│ ├── theme.min.js
│ ├── themes
│ ├── tinymce.js
│ └── tinymce.min.js
from express-static-gzip.
could this be causing an issue:
app.get('/include_public/*', function (req, res) {
res.sendFile( __dirname + req.path);
});
from express-static-gzip.
If it is placed before the part registering expressStaticGzip it would definitly be an issue.
You should not need this part if you use expressStaticGzip, as it would serve all non gziped files in your directory as well.
from express-static-gzip.
It comes after, and after more research, I cannot get anything to console.log from there anyway
from express-static-gzip.
I just don't seem to be able to get this to work :(
from express-static-gzip.
do I have this right? It is not crashing my app, so I figure, yes.
var expressStaticGzip = require('express-static-gzip');
from express-static-gzip.
Yes that's totally correct. So I tried reconstructing your apps code and build some rudimentary code snippet below. You might want to try commenting out the part i commented.
var expressStaticGzip = require('express-static-gzip');
// app.get('/include_public/*', function (req, res) {
// res.sendFile( __dirname + req.path);
//});
app.get('/', expressStaticGzip(__dirname + '/include_public'));
Using this:
app.get('/', expressStaticGzip(__dirname + '/include_public'));
Should do the following. Servce static files on each request that is send to the root of your server. Something like 'mydomain.com/index.html' or 'mydomain.com/bootstrap.css'. In case the browser supports gzip, it will look for the '<requested-file>.gz' [Edit: wrongly wrote .gzip].
Looking at your initial code snippet:
app.use('/include_public', expressStaticGzip(__dirname + '/include_public/'));
This would serve only static files, that where requested from this url: 'mydomain.com/include_public/index.html'. Maybe this helps clearify some stuff.
from express-static-gzip.
You might also want to have a look at the e2e tests i wrote for this middleware, as these show how simple the setup should be. You might be able to find some more information about server setup and how the client requests should look in this test.
You might want to start with the setupServer function from the test.
from express-static-gzip.
it occurs to me that this might be a problem:
app.use(express.static("include_public"));
or am I way off base?
from express-static-gzip.
I can't make sense of the e2e.spec file
I appreciate your help. I am giving up on this for now
from express-static-gzip.
@phpmydev, yes you need to add path module. Seems like issue with directory structure..Could you please move your .gz file under /include_public and restart your node server.Hope this will work
from express-static-gzip.
I had added the path module, the file was under include_public - I have uncompressed it and it serves up the css just fine. We were looking to speed up our app is all. Thank you for your suggestions @ramspassion!
from express-static-gzip.
If possible you could zip your app, with just the essential part (server.js? and static files in the directory structure you have right now). I might find some time on the weekend to have a look.
You should remove any customer related stuff so.
from express-static-gzip.
Actually, we are a federal contractor - I cannot share any code, but thanks!
from express-static-gzip.
Closing, due to inactivity.
from express-static-gzip.
Related Issues (20)
- Rename "indexFromEmptyFile" to "index" HOT 4
- single-page router rendering HOT 2
- Checking for compressed versions of a file when requested, rather than at startup will alleviate several potential problems HOT 9
- brotli does not work HOT 12
- silently does not work if the static files folder path contains ".gz" HOT 2
- findAllCompressionFiles errors out if unable to access folder HOT 4
- Header content type always return gzip HOT 2
- Make passing "index" to "serve-static" optional HOT 4
- Change to just middleware? HOT 1
- Can't serve gzip files HOT 6
- Compressed files from nested folders not served HOT 1
- MIME type is 'application/gzip' instead of 'application/javascript' HOT 2
- express static gzip doesnt work in vue ssr HOT 10
- Expose serveStatic.mime HOT 2
- Invalid URI Component in Path HOT 6
- 'maxAge' does not exist in type 'ExpressStaticGzipOptions' HOT 2
- Tries to use .index file when it doesn't exist HOT 1
- Browser preferences takes preference over server HOT 2
- Ensure Https protocol for serving brotli HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from express-static-gzip.