We have fabricated gradient-grafted nanofoam films that are able to record the presence of volatile chemical compounds in an offline regime. In essence, the nanofoam film (100-300 nm thick) is anchored to a surface cross-linked polymer network in a metastable extended configuration that can relax back to a certain degree upon exposure to a chemical vapor. The level of the chain relaxation is associated with thermodynamic affinity between the polymer chains and the volatile compounds. In our design, the chemical composition of the nanofoam film is not uniform; therefore, the film possesses a gradually changing local affinity to a vapor along the surface. Upon vapor exposure, the nonuniform changes in local film morphology provide a permanent record or "fingerprint" for the chemical event of interest. This permanent modification in the film structure can be directly detected via changes not only in the film surface profile but also in the film optical characteristics. To this end, we demonstrated that sensing/recording nanofoam films can be prepared and interrogated on the surfaces of optical waveguides, microring optical resonators. It is important that the initial surface profile and structure of the nanofoam film are encrypted by the distinctive conditions that were used to fabricate the film and practically impossible to replicate without prior knowledge.