Leverage browser caching - PageSpeed Insights issue [duplicate] - .htaccess

This question already has answers here:
PageSpeed Insights 99/100 because of Google Analytics - How can I cache GA?
(20 answers)
Closed 4 years ago.
I am getting this error:
Leverage browser caching
Setting an expiry date or a maximum age in the HTTP headers for static resources instructs the browser to load previously downloaded resources from local disk rather than over the network.
Leverage browser caching for the following cacheable resources:
http://www.google-analytics.com/analytics.js (2 hours)
This is my google analytics js code:
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-35812981-4', 'auto');
ga('send', 'pageview');
</script>
There is only a very few question about this message on stackoverflow and the answer from them is not working for me. How can i rid of this message ? My score is 99/100, this is the only one. Can you help me with this ?

A possible solution is to use this service. It provides a cached copy of the analytics.js that has a bigger time. You would just need to change the analytics link to this one: http://www.schedule-analytics.com/analytics.js

Related

Google Analytics/Google Ads and Content Security Policy

It's not easy to get Google Analytics/Google Ads working with CSP. I checked out a number of SO articles including this one, but wanted to see if there was another approach.
I found a pretty easy way to do it in this article, and wanted to post it here in case it may be useful to others. I'll post it here as an answer.
I found a pretty easy way to do it in this article:
...move the Google Analytics code snippet to an external code file,
hosted on a domain that is already allowlisted by your script-src
directed, such as the primary domain of your website.
The script originally supplied by Google was:
<!-- Google tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-##########">
</script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-##########');
</script>
I went to https://www.googletagmanager.com/gtag/js?id=UA-##########, downloaded the script, and added this to the bottom of it:
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-##########');
I saved it to my website. I added this:
<script async src="/script-saved-to-my-website.js"></script>
...inside the head section. (Google ads seems to want it inside the head section for some reason).
I added csp policy as described in the above article.
I connected Google Analytics 4 to Google Ads using the "connect to Google ads" feature I found in Google Analytics. Note: you have to have Google Ads in Expert mode, not Smart mode, for this to work.
I set up a Conversion goal on Google Ads.
And... it's working. :) I can see my stats on Google Analytics and my conversions on Google Ads.

Home Assistant Sensor API Specification, how to set a unique_id via REST?

Years ago I built a temperature sensor that would push (http post) readings to a server / dashboard system I had written. In lieu of expanding requirements, I've decided to switch to Home Assistant as my backend. Though it is possible to send the data to HA, the documentation is spotty. Namely I'm looking for the full JSON for the post body (an OpenAPI spec would be nice) and more details around how sensors function, and things "like can I set a unique_id so that they are editable in HA?", etc.
So far I've been working off the little bits of information around the API, some examples, and inferences from other documents for the python api (internal server code).
REST API
https://developers.home-assistant.io/docs/api/rest/
Sensor post info from HTTP integration
https://www.home-assistant.io/integrations/http/#sensor
General Sensor Docs
https://www.home-assistant.io/integrations/sensor#device-class
Perhaps what you're looking for is value_json?
Here's how I'm fetching value out of a simple webserver which returns this basic json object { key: value }, although one difference is that I'm polling and using GET.
rest:
- resource: http://192.168.0.122/status
sensor:
- name: "Data from my server"
value_template: "{{ value_json.key }}"
Tip: Go to Developer Tools -> Template for a sandbox-like environment where you can rapidly prototype your value_template

X-Content-Type-Options Header Missing Website Application SocketIO

i am developing an nodejs express application that is running in the ibm cloud. Via Hostedscan i tested my application for security issues.
im getting follwing result:
"X-Content-Type-Options Header Missing"
The Anti-MIME-Sniffing header X-Content-Type-Options was not set to 'nosniff'. This allows older versions of Internet Explorer and Chrome to perform MIMEsniffing on the response body, potentially causing the response body to be interpreted and displayed as a content type other than the declared content type.
Current (early 2014) and legacy versions of Firefox will use the declared content type (if one is set), rather than performing MIME-sniffing.
my url that have a risk:
https://xxx.xxx.xxx.xxx:xxxxx/socket.io/socket.io.js
its a get method
i implemented following solution
(server.js)
const helmet = require("helmet")
.....
app.use(helmet.noSniff())
with this code a part of the security issues where gone like :
https://xxx.xxx.xxx.xxx:xxxxx/
https://xxx.xxx.xxx.xxx:xxxxx
https://xxx.xxx.xxx.xxx:xxxxx/chatroom
but the secuirty risk with https://xxx.xxx.xxx.xxx:xxxxx/socket.io/socket.io.js is still reminding.
i also tryed in my index.html following, because i thought the security risk could be because my client is also interacting with socket.io
<script
src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.5.1/socket.io.js"
integrity="sha512-xxxxxxxx....."
crossorigin="anonymous">
</script>
does anyone have an approach?

Angular 8: Loading module from "url" was blocked because of a disallowed MIME type (“text/html”)

I have created the application in Angular 8 and Node 12.
After creating angular 8 build I am facing this problem while opening a new tab or page reload I have searched all around the internet did not found any solution.
Firefox console:
Google Chrome console:
TSCONFIG:
Other than that everything works.
Thanks in advance.
I was roaming around the internet I found the answer here:
Angular 2 Remove Hash (#) from the URL
So basically there was a # URL problem which I come across and by setting up RouterModule.forRoot(routes, { useHash: true }) I am able to successfully run the application.
Thank you guys for helping me

CouchDB: custom error page

Is there a way to customize error pages in CouchDB, particularly in couchapp?
When I try to load URL with undefined/misspelled view
http://localhost:5984/database/_design/app/_view/sample
CouchDB 1.2 just closes the connection:
Error 324 (net::ERR_EMPTY_RESPONSE): The server closed the connection without sending any data.
I'd like to customize this behavior.
A partial answer was found here: http://wiki.apache.org/couchdb/Advanced_Shows_and_Lists_Throwing_Redirects

Resources