Coder Social home page Coder Social logo

Comments (19)

ramspassion avatar ramspassion commented on June 14, 2024

Hi, please try with below option
app.use('/', expressStaticGzip(path.join(__dirname,'include_public')));

from express-static-gzip.

rvwhitney avatar rvwhitney commented on June 14, 2024

tried it - I get "Cannot GET /"
and I had to add require('path')

from express-static-gzip.

rvwhitney avatar rvwhitney commented on June 14, 2024

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.

tkoenig89 avatar tkoenig89 commented on June 14, 2024

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.

rvwhitney avatar rvwhitney commented on June 14, 2024

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.

rvwhitney avatar rvwhitney commented on June 14, 2024

could this be causing an issue:

app.get('/include_public/*', function (req, res) {
	res.sendFile( __dirname + req.path);
});

from express-static-gzip.

tkoenig89 avatar tkoenig89 commented on June 14, 2024

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.

rvwhitney avatar rvwhitney commented on June 14, 2024

It comes after, and after more research, I cannot get anything to console.log from there anyway

from express-static-gzip.

rvwhitney avatar rvwhitney commented on June 14, 2024

I just don't seem to be able to get this to work :(

from express-static-gzip.

rvwhitney avatar rvwhitney commented on June 14, 2024

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.

tkoenig89 avatar tkoenig89 commented on June 14, 2024

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.

tkoenig89 avatar tkoenig89 commented on June 14, 2024

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.

rvwhitney avatar rvwhitney commented on June 14, 2024

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.

rvwhitney avatar rvwhitney commented on June 14, 2024

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.

ramspassion avatar ramspassion commented on June 14, 2024

@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.

rvwhitney avatar rvwhitney commented on June 14, 2024

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.

tkoenig89 avatar tkoenig89 commented on June 14, 2024

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.

rvwhitney avatar rvwhitney commented on June 14, 2024

Actually, we are a federal contractor - I cannot share any code, but thanks!

from express-static-gzip.

tkoenig89 avatar tkoenig89 commented on June 14, 2024

Closing, due to inactivity.

from express-static-gzip.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.