Rails assets still being served in single file in development - javascript

In my development.rb I have
config.assets.debug = true
config.assets.compress = false
However my assets are being served in single files"
images/application.js
javascripts/application.css
I have deleted the cache files from tmp/cache & restarted the server but assets are still served in a single file (not compressed by the way).
I'm running Rails 3.2.13.
Has anyone got any ideas?

Related

how to gzip or compress a .json file and use it in the frontend .js

i have big json file that i load in the index.js On page load (javascript) file which leads to increase in the time of loading the page.
What should i use to reduce this so that the page loads fast?
You need to enable gzip on your server level, In configuration compressableMimeType you can specify which type of data to be compressed.
<Connector port="8090" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8444"
compression="on" compressableMimeType="text/html,
text/xml,text/plain,text/javascript,text/css,application/json" />
You can visit http://viralpatel.net/blogs/enable-gzip-compression-in-tomcat/ for configuration steps
In your Apache configuration, set mod_deflate parameters. See here for complete doc
Depending on your configuration, apache config could be located:
Windows C:\Program Files\Apache Group\Apache2\conf\httpd.conf
Linux: /etc/httpd/conf/httpd.conf

Azure Website 404 (Not Found) on PHP Resources

I'm new to all things coding and have tried to use Azure to host a web app. The app is JavaScript using PHP to process MYSQL data. Everything works locally as expected. But when I try to access the app where it's hosted, I see 404 (Not Found) errors on all of my calls to .php files.
I'm using jQuery's getJSON to get data:
$.getJSON('bin/myFile.php', function(data) {
// Process data
})
Then in the browser console I see:
GET https://mysite.azurewebsites.net/bin/myFile.php 404 (Not Found)
But, if I move that file to the root directory and drop the bin/ from my call, it works perfectly. All other calls to files in folders work fine (images, scripts, styles), only the php files in the bin folder return this error.
Anyone know why?
Answer from comments:
Try renaming your bin folder. That is normally where binary files are placed in a windows web app environment, so it's possible the Azure server is configured to not serve any files from that location –
Rory McCrossan
Sep 26 '17 at 16:22

Symfony assteic resources not cached by the browser

I am using the assetic manager to serve my css and js files however the browser is loading them on every page request instead of caching them locally. I have checked the Last-Modified response header when fetching the css/js file and it is the same time as the request, which I assume is why it is returning the full file with a 200 response instead of a 304.
I am using the production environment with the following config:
assetic:
debug: "%kernel.debug%"
use_controller: false
filters:
cssrewrite: ~
lessphp:
apply_to: "\.less$"
formatter: "compressed"
preserve_comments: false
How can I get Symfony to send the Last-Modified time of the created assetic file so that it is cached in the browser?
Assetic or Symfony do not set any Last-Modified cache headers for any asset files. Assetic just generates any needed css/js files and modifies any link that uses them, but then they are served by the web server as any other static file. You should look into your web server configuration to find out how to set Last-Modified headers for static files.

Rails 3.2 continues to serve OLD version of JavaScript asset file - Development Env

I have a Rails 3.2 application, and in it I have a Javascript file (app.'s) which appears to be 'stuck' at a particular, past, version. I've updated the file many times, changing its contents significantly, and being sure each time to Save the file - to no effect. I've rebooted the machine multiple times (thinking at least THAT should clear out the cobwebs) all to no avail. I'm at my wits end trying to think of ways to un-stick this.
I can see that the file is being served, each time I visit the page:
Started GET "/dev-assets/app.js?body=1" for 172.16.0.12 at 2014-04-24 16:49:36 -0700
Served asset /app.js - 200 OK (1ms)
And then later in the same test run (not modified - as I expect):
Started GET "/dev-assets/app.js?body=1" for 172.16.0.10 at 2014-04-24 16:51:31 -0700
Served asset /app.js - 304 Not Modified (0ms)
But STILL it has the old contents (which, have a call to 'location.assign' which has since been removed - so the behavior should be significantly different than what I'm seeing.
I have these settings in my development.rb file (but this is not the complete file):
config.cache_classes = false
# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true
# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# From Rails issue 10091 - attemp to keep from loading scripts
# multiple times
config.assets.prefix = "/dev-assets"
# Do not compress assets
config.assets.compress = false
# Expands the lines which load the assets
config.assets.debug = true
# Workaround documented in Rails issue 4145
config.serve_static_assets = false
Anyone have any idea how I can clear this old file?
Note - this is very similar to:
Clear the cache from the Rails asset pipeline
But none of those suggestions have helped me.
This isn't a Rails problem. Rails is serving up the correct file, as verified by by fetching the file in the browser:
http://localhost:3000/dev-assets/app.js

Compiled files not getting fingerprint rails

I have a number of environments where I deploy an application. In two of them I deploy the following configuration for assets:
config.assets.enabled = true
config.assets.compress = false
config.assets.compile = true
config.assets.precompile = false
config.assets.digest = true
config.assets.debug = false
config.serve_static_assets = true
My applicaton.js, that compiles a number of .js files on it, is not getting a fingerprint, so I don't serve changes to customers that have already cached it.
The web page then serves all assets precompiled with fingerprint except application.js
Where can I start to look for this failure?
The culprit is the following option :
config.assets.compile = true
It will live compile each file without fingerprint and serve them straight for rails
You should set it to false and use config.assets.precompile which should contain the list of all precompiled filed :
config.assets.precompile += %w(application.js foo.js)
Then don't forget to run rake assets:precompile in your deployment task to recompile new assets.
On a side note, you should also set config.serve_static_assets to false and let nginx / apache / your web server handle it for you, serving assets from rails has a big overhead.

Categories